I am trying to update one particular field in the document. Here is my code:
module.exports.editAndUpdate = function(playerVideo, callback) {
console.log(playerVideo.vidName);
var newVidId = toString(playerVideo.vidId);
myModel.findById(newVidId, function(err, doc) {
if(err) throw err;
doc.vidName = playerVideo.vidName;
doc.save(callback);
});
}
Here playerVideo is a document, vidName and vidId are its fields.
Instead of doc.vidName = playerVideo.vidName, if I use doc.vidName = "Hey", then it is working perfectly fine. I used the typeof method and checked if playerVideo.vidName is a String and yes, it is.
Please help me solve this. Thanks for any suggestions :)
For me, the issue occurred when I was updating a nested object, which had a fullstop in the key value.
e.g.
"$set": {
"some.field": {
"validuser": "this works",
"invalid.user": "this breaks mongo"
}
}
MongoDB doesn't support keys with a dot, and was providing this cryptic error:
cannot set property 'value' of null
Solution - don't store keys with a fullstop in it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With