I am using mongo db on nodejs. I am trying to update record by unique key. When I prepare arguments pro grammatically, getting failed. If I hard coded the set params, working fine.
How to create $set parameters in run time on node.js server.
code:
var collection = db.collection('test', function(err, collection) {
var args = "{field1: 5}";
collection.update({unique_key_field: val}, {$set: args}, w:1, function(e, r) {
//always failed.
// If I copy {field1: 5} at args place, it's updating properly.
});;
});
args
needs to be an actual object, not a stringified object:
var args = { field1: 5 };