What is wrong with the code below?
db.get().collection('bars').findAndModify({
barID: req.body.button
},{
$push: {
usersfbID: req.body.profileUser[0].facebookID,
usersDocID: req.body.profileUser[0]._id
}
},{
new: true
}, function(err, doc){
if(err){
throw err;
}if(doc){
console.log('Existing document updated successfully');
console.log(doc);
}
});
I always get the same error,
MongoError: exception: nextSafe(): { $err: "Can't canonicalize query: BadValue bad sort specification", code: 17287 }
What am I doing wrong? Am I misusing the $push operator? Do I need to provide quotes around some of the key value pairs? This findAndModify method is driving me crazy. I have absolutely no idea what I am doing wrong.
Note: I have been through the other questions on SO regarding findAndModify, but none of those solutions is working for me. I'm sure its a small error regarding the syntax for the function.