0

This is my working query:

collection.update({ _id: '124'}, {$addToSet: {'data.dropdowns.accessRoles': req.body.newItem}}, function(err, results) {
                   //
                });

I want to change data.dropdowns.accessRoles according to input string. Input variable is stored in req.body.listName. I tried this, but it didn't work:

{$addToSet: {'data.dropdowns.req.body.listName': req.body.newItem}}

Any ideas?

1
  • var setValue = {}; setValue['data.dropdowns' + req.body.listName] = 0; I defined path like this. How do I use this in my query? {$addToSet: {setValue: req.body.newItem}} doesn't work. I don't know how to use $set. Commented Jul 21, 2014 at 19:32

1 Answer 1

1

Assembly your $addToSet object programmatically:

var addToSet = {};
addToSet['data.dropdowns.' + req.body.listName] = req.body.newItem;
collection.update({ _id: '124'}, {$addToSet: addToSet}, function(err) {...});
Sign up to request clarification or add additional context in comments.

Comments

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.