[SERVER-13883] findAndModify() cannot take an empty update object, but update() can Created: 08/May/14  Updated: 11/Jul/16  Resolved: 29/May/14

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.4.10, 2.6.1
Fix Version/s: 2.7.2

Type: Bug Priority: Major - P3
Reporter: Matt Dannenberg Assignee: J Rassi
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-12266 Update no longer allows empty modifie... Closed
is related to SERVER-13688 Picky errors from 2.6 are needlessly ... Closed
is related to SERVER-13884 $set: {} is now rejected by the updat... Closed
Operating System: ALL
Steps To Reproduce:

> db.foo.update({},{},true)
WriteResult({
	"nMatched" : 0,
	"nUpserted" : 1,
	"nModified" : 0,
	"_id" : ObjectId("536beb62fe2ac487fb241614")
})
 
> db.foo.findAndModify({query:{_id: ObjectId("536beb62fe2ac487fb241614")},update:{},upsert:true})
2014-05-08T17:10:23.774-0400 findAndModifyFailed failed: { "ok" : 0, "errmsg" : "need remove or update" } at src/mongo/shell/collection.js:614

Participants:

 Description   

> db.foo.update({},{},true)
WriteResult({
	"nMatched" : 0,
	"nUpserted" : 1,
	"nModified" : 0,
	"_id" : ObjectId("536beb62fe2ac487fb241614")
})
 
> db.foo.findAndModify({query:{_id: ObjectId("536beb62fe2ac487fb241614")},update:{},upsert:true})
2014-05-08T17:10:23.774-0400 findAndModifyFailed failed: { "ok" : 0, "errmsg" : "need remove or update" } at src/mongo/shell/collection.js:614



 Comments   
Comment by Githook User [ 29/May/14 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-13883 findAndModify command should accept update:{}
Branch: master
https://github.com/mongodb/mongo/commit/a7bae827a56cf2d80d65a1c26b135f957d0b64f0

Comment by Githook User [ 29/May/14 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-13883 findAndModify return null if !new and doc not found

Fixes an edge case where findAndModify would return {} instead of null
if the doc was not found (specifically: if sort was specified and the
update resulted in an upsert).
Branch: master
https://github.com/mongodb/mongo/commit/2e623309d5066e9505da758b0deac955cc10ac80

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