0

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.

 });;
});    

1 Answer 1

1

args needs to be an actual object, not a stringified object:

var args = { field1: 5 };
Sign up to request clarification or add additional context in comments.

1 Comment

How to send multiple arguments to $set? any idea?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.