This is related to https://jira.mongodb.org/browse/SERVER-4157
If the _id value in the query document does not match the _id value in the update document, an empty document will be returned.
To reproduce: (in 1.8.4 or 2.0.1)
> db.test.drop()
true
> db.test.findAndModify({ "query" :
, "update" :
{ "_id" : 1, "name" : "Object 1"}, "upsert" : true, "new" : true } );
{ } // an empty document is returned
> db.test.find()
> db.test.findAndModify({ "query" :
{ "_id" : 2, name:"blah"}, "update" :
{ "_id" : 2, "name" : "Object 2"}, "upsert" : true, "new" : true } );
{ "_id" : 2, "name" : "Object 2" } // the expected document is returned
>
- duplicates
-
SERVER-6913 update allows upsert to "modify" _id
- Closed