[SERVER-4163] findAndModify returns an empty document with "new" : true flag if the _id value in the query document does not match the _id value in the update document. Created: 27/Oct/11  Updated: 07/Mar/14  Resolved: 18/Sep/12

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 1.8.4, 2.0.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Barrie Segal Assignee: Eliot Horowitz (Inactive)
Resolution: Duplicate Votes: 0
Labels: find
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-6913 update allows upsert to "modify" _id Closed
Operating System: ALL
Participants:

 Description   

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" :

{ "_id" : 0}

, "update" :

{ "_id" : 1, "name" : "Object 1"}

, "upsert" : true, "new" : true } );
{ } // an empty document is returned
> db.test.find()

{ "_id" : 1, "name" : "Object 1" }

> 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
>


Generated at Thu Feb 08 03:05:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.