[SERVER-6659] findAndModify errors when upserting on non-existent document and original query can't find doc Created: 31/Jul/12  Updated: 11/Jul/16  Resolved: 01/Aug/12

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.1.0, 2.1.1, 2.1.2, 2.2.0-rc0
Fix Version/s: 2.2.0-rc1

Type: Bug Priority: Major - P3
Reporter: Remon van Vliet Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: findAndModify
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All


Backwards Compatibility: Major Change
Operating System: ALL
Participants:

 Description   

The following findAndModify succeeds on 2.0 and lower and fails on 2.1 and higher :

db.test.findAndModify({query:

{f:1}

, update:{$set:{f:2}}, upsert:true, new:true})

With the following (somewhat vague) error : uncaught exception: findAndModifyFailed failed: "exception: assertion src\\mongo\\db\\commands
find_and_modify.cpp:146"

The expected behaviour would be that this operation returns

{ "_id" : ... , "f" : 2 }

but as shown it fails.



 Comments   
Comment by auto [ 01/Aug/12 ]

Author:

{u'date': u'2012-07-31T23:15:15-07:00', u'email': u'eliot@10gen.com', u'name': u'Eliot Horowitz'}

Message: SERVER-6659 - fix find_and_modify when upserting a new doc and original query won't work anymore
Branch: master
https://github.com/mongodb/mongo/commit/cbc8b6e716a92357655ff9a33d1c5e1e274744a6

Comment by Remon van Vliet [ 31/Jul/12 ]

Confirmed. I should've added a bit more description It only occurs when MongoDB is actually attempting the upsert (rather than the update for an existing document).

Comment by Ian Whalen (Inactive) [ 31/Jul/12 ]

thanks for catching that remon. can you confirm it's just upserting on non-existing doc that fails for you? upsertng against an existing doc appears to work on my end.

Comment by Remon van Vliet [ 31/Jul/12 ]

Noticed the issue name change. The issue is not related to the collection existing or not. :

mongos> db.test.save({})
mongos> db.test.findAndModify({query:

{f:1}

, update:{$set:{f:2}}, upsert:true, new:true})
Tue Jul 31 16:39:37 uncaught exception: findAndModifyFailed failed: "exception: assertion src\\mongo\\db\\commands
find_and_modify.cpp:146"

Comment by Kristina Chodorow (Inactive) [ 31/Jul/12 ]

To reproduce:

> db.foo.drop()
> db.foo.findAndModify({query:{f:1}, update:{$set:{f:2}}, upsert:true, new:true})

Output:

Tue Jul 31 10:28:26 [conn1]  test.foo Assertion failure Helpers::findOne( ns.c_str() , queryModified , doc ) src/mongo/db/commands/find_and_modify.cpp 146
0xe40b9f 0x9b0568 0xc76502 0xaee044 0xaed939 0xaee2c7 0xe43497 0xe44666 0xe44c55 0xd9667e 0xd9b085 0xc37cba 0xc38c75 0x95bef1 0xd7c295 0x7fbfba2a2d8c 0x7fbfb9644c2d
 ./mongod(_ZN5mongo15printStackTraceERSo+0x27) [0xe40b9f]
 ./mongod(_ZN5mongo10logContextEPKc+0x5e) [0x9b0568]
 ./mongod(_ZN5mongo12verifyFailedEPKcS1_j+0x122) [0xc76502]
 ./mongod(_ZN5mongo16CmdFindAndModify17runNoDirectClientERKSsRKNS_7BSONObjES5_S5_bbbRNS_14BSONObjBuilderE+0x43c) [0xaee044]
 ./mongod(_ZN5mongo16CmdFindAndModify17runNoDirectClientERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb+0x369) [0xaed939]
 ./mongod(_ZN5mongo16CmdFindAndModify3runERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb+0x135) [0xaee2c7]
 ./mongod(_ZN5mongo12_execCommandEPNS_7CommandERKSsRNS_7BSONObjEiRNS_14BSONObjBuilderEb+0x92) [0xe43497]
 ./mongod(_ZN5mongo11execCommandEPNS_7CommandERNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb+0xf19) [0xe44666]
 ./mongod(_ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi+0x358) [0xe44c55]
 ./mongod(_ZN5mongo11runCommandsEPKcRNS_7BSONObjERNS_5CurOpERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi+0x46) [0xd9667e]
 ./mongod(_ZN5mongo8runQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_+0x363) [0xd9b085]
 ./mongod() [0xc37cba]
 ./mongod(_ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE+0x315) [0xc38c75]
 ./mongod(_ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE+0xdd) [0x95bef1]
 ./mongod(_ZN5mongo3pms9threadRunEPNS_13MessagingPortE+0x4a1) [0xd7c295]
 /lib/x86_64-linux-gnu/libpthread.so.0(+0x6d8c) [0x7fbfba2a2d8c]
 /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7fbfb9644c2d]
Tue Jul 31 10:28:26 [conn1]
 
***aborting after verify() failure as this is a debug/test build
...

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