I'm currently trying to figure out how to add a specific Mongo command to my JSON object. Normally, adding regular strings or objects is straightforward, but I'm struggling with this particular command:
$set : { "author" : req.body.name }
Simply assigning it like myJsonObject.author = "$set..."
isn't working as expected.
If anyone can assist with this issue, I'd greatly appreciate it. Also, if you have any insights on updating multiple items in a MongoDB update using a JSON object, please share your knowledge. Currently, I'm only able to update the last item in the object, which is causing some trouble for me.
Here's an example of my JSON object:
updateItem = {
$set : { "name" : "Squid bonobo" },
$set : { "author" : "Mardy Bum" }
};
and here's the code snippet that performs the update:
updateData.update(searchItem, updateItem, false, true, function(err, results) {
console.log(results);
db.close();
});
If you have experience or solutions to these issues, your help would be invaluable. Thanks in advance!
Cameron