Answer the question
In order to leave comments, you need to log in
How to update using compound field name in MongoDB via NodeJS?
there is a table like this:
{
"_id" : ObjectId("5379b1b81cdcaf4db70cc16f"),
"hash" : "123",
"serverList" : {
"server1" : {
"host": "http://192.168.5.138:80/",
"url" : "/123/",
"ssid" : "321"
},
"server2" : {
"host": "http://192.168.5.144:80/",
"url" : "/123/",
"ssid" : "321"
}
}
}
var data = JSON.parse(params).result, ssid = 'serverList.'+server[i]+'.ssid', url = 'serverList.'+server[i]+'.url';
leaders.update({'hash':request.cookies.hash}, {'$set':{ ssid: data['ssid'], url: data['sessionurl']}}, function(e, d) {
console.dir(e);
console.dir(d);
});
// Где server[i] это 'server1' или 'server2', а в data приходят нужные url и ssid
Answer the question
In order to leave comments, you need to log in
So far I decided to form a change request as an object ...
var $set = {};
$set['$set'] = {};
$set['$set']['serverList.'+i+'.ssid'] = data['ssid'];
$set['$set']['serverList.'+i+'.url'] = data['sessionurl'];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question