Info
If a multi:true update is run such that it fails halfway the resulting nModified / nMatched fields appear to always be set to zero (and the appropriate error given) even if documents have been modified.
Top User Comments
david.storch commented on Mon, 29 Aug 2016 14:47:03 +0000:
Closing as a duplicate of SERVER-15292.
Steps to Reproduce
db.test.drop()
db.test.ensureIndex({num:1},{unique:true})
db.test.insert([{num:0},{num:2},{num:4},{num:6},{num:7},{num:10}])
db.test.update({},{$inc:{num:1}},{multi:true})
Gives:
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 11000,
"errmsg" : "E11000 duplicate key error collection: mt.test index: num_1 dup key: { : 7.0 }"
}
})
But...
> db.test.find({},{_id:0})
{ "num" : 1 }
{ "num" : 3 }
{ "num" : 5 }
{ "num" : 6 }
{ "num" : 7 }
{ "num" : 10 }
3 documents were modified. We would expect "nMatched" and "nModified" to be at least 3.