Connecting to our Mongo instance using the CLI, you can use the update modifier operators just fine:
db.users.update ({nickname: 'mcoalson'}, {"$ addToSet": {room_ref: "b"}}) db.users.update ({nickname: 'mcoalson'}, {"$ addToSet": { room_ref: "c"}}) db.users.findOne ({nickname: 'mcoalson'}) {"_id": ObjectId ("4de5e9e982e9556c2a000003"), "nickname": "mcoalson", "room_ref": ["A" , "D", "B", "C"]}
However, doing the same in node.js in the same document, there are no results.
db.User.update({'nickname': 'mcoalson'}, {"$pullAll": {'room_ref': ["b"]}});
db.User.update({'nickname': 'mcoalson'}, {"$addToSet": {'room_ref': "f"}});
"room_ref": ["A", "D", "B", "C"]
Clearly, “b” was not deleted, and “f” was not added. I tried all conceivable quotation scenarios that I could think of, but nothing changes. Can I use find () and findOne () from node.js code and am I using the same credentials, any tips?
source
share