0

In this function I pass in an ID variable and a name variable, I use the ID to pick out the correct table and want to set an array using the value inside of the name variable. Currently It's adding just "name" as an object key, how can I tell it to use the value inside of my name variable as the Object Key?

function addnewuser(name, id){ // add users
          console.log(id);
          db.collection('newcon').update({_id: id}, {"$set": { name: [] }});
          ret(id);
        }
chridam
  • 100,957
  • 23
  • 236
  • 235
Ajax jQuery
  • 357
  • 1
  • 5
  • 19
  • 2
    You probably will need to [build $set modifier programmatically][1]. [1]: http://stackoverflow.com/questions/12184626/nodejs-mongo-insert-into-subdocument-dynamic-fieldname – kaaposc Jun 14 '15 at 21:08
  • @kaaposc When I write this it is throwing an error back at me: https://gist.github.com/InternetExplorer7/199e5f6ed5ff719c0d04 – Ajax jQuery Jun 14 '15 at 22:39
  • You would use the `modifier` that you've defined outside like this: `db.collection('newcon').update({_id: id}, modifier);` – laggingreflex Jun 14 '15 at 22:46

0 Answers0