Reputation: 1855
Say I'm doing a single-collection, multi-document operation through Mongoose such as
// all my_model doc's have flag==false here
my_model.update({flag:false}, {flag:true}, {multi:true}, function(err) {
if (err) {
// what can I assume here?
}
});
What can I say about my my_model
documents in the event of an error? Will some have flag == true
? Or is it an atomic operation in the sense that if there is an error, none of the updates will occur?
Is this behavior consistent amongst other multi-document operations with a single collection (ex remove()
) ? Is this the price I pay for non-ACIDity ?
edit: From the mongodb docs:
The modification of a single document is always atomic, even if the write operation modifies multiple sub-documents within that document. For write operations that modify multiple documents, the operation as a whole is not atomic, and other operations may interleave.
Since other operations may interleave, I can only assume then that in the event of an error, the data would be in a transtional state, with some docs updated and others not.
Upvotes: 1
Views: 65
Reputation: 936
Your intuition is correct. If there is an error during a multi-document update, you may have a situation in which some of the documents have flag == true
and others have flag == false
.
Upvotes: 1