Info
"nModified" should be 0 in the following case, but it's 1:
> db.collection.find()
{ "_id" : 1, "a" : 1 }
> db.runCommand({update: 'collection', updates: [{q: {_id: 1}, u: {_id: 1, a: 1}}]})
{ "ok" : 1, "nModified" : 1, "n" : 1 }
nModified is 0 as expected if:
the update uses $set instead of a whole-document replace
the _id is an ObjectId instead of an integer
the query is on a field besides _id
The behavior is intermittent, as seen in this shell session:
> db.collection.find()
{ "_id" : 1, "a" : 1 }
> db.runCommand({update: 'collection', updates: [{q: {_id: 1}, u: {_id: 1, a: 1}}]})
{ "ok" : 1, "nModified" : 1, "n" : 1 }
> db.collection.drop()
true
> db.collection.insert({_id: 1, a: 1})
WriteResult({ "nInserted" : 1 })
> db.runCommand({update: 'collection', updates: [{q: {_id: 1}, u: {_id: 1, a: 1}}]})
{ "ok" : 1, "nModified" : 0, "n" : 1 }
Top User Comments
ian@10gen.com commented on Fri, 26 Apr 2019 13:32:45 +0000:
Switching "Drivers Changes Needed" from "Maybe" to "Not Needed" since this was closed as something other than Fixed.
jesse commented on Thu, 16 Oct 2014 20:44:09 +0000:
Can no longer reproduce.
ramon.fernandez commented on Mon, 29 Sep 2014 21:42:25 +0000:
I'm was not able to reproduce this behavior using this loop:
$ cat test.js
db.collection.drop()
db.collection.insert({_id:1, a:1})
for (i = 0; i< 1000; i++) {
var n = db.runCommand({update: 'collection', updates: [{q: {_id: 1}, u: {_id: 1, a: 1}}]})
if (n.nModified == 1) {
print ("Wrong!")
}
}
$
$ mongo < test.js
MongoDB shell version: 2.6.3
connecting to: test
true
WriteResult({ "nInserted" : 1 })
bye
jesse, are you still able to reproduce this?