[SERVER-2757] findAndModify should only return false if there is an error, not missing doc. findAndRemove throws an exception when no record found Created: 14/Mar/11  Updated: 12/Jul/16  Resolved: 04/Apr/11

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: None
Fix Version/s: 1.9.0

Type: Improvement Priority: Major - P3
Reporter: Alexander Azarov Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MongoDB 1.6.5


Backwards Compatibility: Minor Change
Participants:

 Description   

findAndRemove throws CommandResult.Failure when no record in the collection found. Problems:

1. Java driver 2.4 returned null in this scenario
2. The exception has code=-5 which makes it indistinguishable from real errors.

Test case: https://github.com/alaz/mongo-java-driver/commit/56478bbefdd99fb97a564a449e99772efc08e7b8



 Comments   
Comment by Mathias Stearn [ 04/Apr/11 ]

Only breaks code that requires throwing an exception on missing object. If callers captured the exception and returned null (as the js shell and python driver do) everything will work as it did before.

Comment by auto [ 04/Apr/11 ]

Author:

{u'login': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: findAndModify command now returns null rather than failing when query doesn't match any objects SERVER-2757

No change in helpers needed since they were catching the error and returning
null anyway
Branch: master
https://github.com/mongodb/mongo/commit/700b3394b1132c185031c6ce6dcab235c0aa62f2

Comment by Eliot Horowitz (Inactive) [ 14/Mar/11 ]

if (!upsert)

{ errmsg = "No matching object found"; return false; }
Generated at Thu Feb 08 03:01:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.