Reputation: 1334
I'm using Meteor and was updating a document and had the code (by mistake):
Programs.update({ _id: id}, { set: { LessonWk1: weekArray }});
Instead of:
Programs.update({ _id: id}, { $set: { LessonWk1: weekArray }});
Turns out when I used 'set' it deleted the document when the update ran. I didn't see any 'set' command in Mongo. Just curious how the documents get deleted from 'set'.
Upvotes: 1
Views: 65
Reputation: 61225
This is the expected behavior as mentioned in the documentation:
If the document contains only field:value expressions, then:
The update() method replaces the matching document with the document. The update() method does not replace the _id value.
This means that your document is replaced bu something like this:
{ _id: id, set: { LessonWk1: weekArray }}
Because it doesn't replace the _id
value you can return the new document using findOne
.
Programs.findOne( { _id: id } )
Upvotes: 1