[SERVER-6913] update allows upsert to "modify" _id Created: 31/Aug/12  Updated: 11/Jul/16  Resolved: 02/Oct/13

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

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Unassigned
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-4157 findAndModify throws exception when _... Closed
is duplicated by SERVER-4163 findAndModify returns an empty docume... Closed
Related
related to SERVER-14286 Additional tests for updates and find... Closed
related to SERVER-18076 Upsert rejected with error if _id ass... Closed
is related to SERVER-6909 verify assertion when new version of ... Closed
Operating System: ALL
Participants:

 Description   

Test:

c = db.c;
c.drop();
 
c.findAndModify( { query:{ _id:1 },
                   update:{ _id:2 },
                   upsert:true,
                   new:true } );

Output:

Fri Aug 31 15:11:22 [conn2] queryModified: { _id: 1.0 }
Fri Aug 31 15:11:22 [conn2]  test.c Assertion failure Helpers::findOne( ns.c_str() , queryModified , doc ) src/mongo/db/commands/find_and_modify.cpp 187
0x108c49ea5 0x108e6e45b 0x108cc3329 0x108b24681 0x108b251d9 0x108b202c3 0x1087627ae 0x108764ca4 0x108765990 0x108e22fa5 0x108e23a7b 0x108cb3dc2 0x108cb8cc0 0x108668387 0x108ad4da3 0x108ad6400 0x108ad6462 0x108ad648d 0x1089883e9 0x10a8db8bf 
 0   mongod                              0x0000000108c49ea5 _ZN5mongo15printStackTraceERSo + 37
 1   mongod                              0x0000000108e6e45b _ZN5mongo10logContextEPKc + 123
 2   mongod                              0x0000000108cc3329 _ZN5mongo12verifyFailedEPKcS1_j + 409
 3   mongod                              0x0000000108b24681 _ZN5mongo16CmdFindAndModify17runNoDirectClientERKSsRKNS_7BSONObjES5_S5_bbbRNS_14BSONObjBuilderE + 3915
 4   mongod                              0x0000000108b251d9 _ZN5mongo16CmdFindAndModify17runNoDirectClientERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 1025
 5   mongod                              0x0000000108b202c3 _ZN5mongo16CmdFindAndModify3runERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 425
 6   mongod                              0x00000001087627ae _ZN5mongo12_execCommandEPNS_7CommandERKSsRNS_7BSONObjEiRNS_14BSONObjBuilderEb + 142
 7   mongod                              0x0000000108764ca4 _ZN5mongo11execCommandEPNS_7CommandERNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb + 6516
 8   mongod                              0x0000000108765990 _ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 1472
 9   mongod                              0x0000000108e22fa5 _ZN5mongo11runCommandsEPKcRNS_7BSONObjERNS_5CurOpERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 117
 10  mongod                              0x0000000108e23a7b _ZN5mongo8runQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_ + 1595
 11  mongod                              0x0000000108cb3dc2 _ZN5mongoL13receivedQueryERNS_6ClientERNS_10DbResponseERNS_7MessageE + 418
 12  mongod                              0x0000000108cb8cc0 _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE + 1136
 13  mongod                              0x0000000108668387 _ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE + 261
 14  mongod                              0x0000000108ad4da3 _ZN5mongo3pms9threadRunEPNS_13MessagingPortE + 2275
 15  mongod                              0x0000000108ad6400 _ZN5boost3_bi5list1INS0_5valueIPN5mongo13MessagingPortEEEEclIPFvS5_ENS0_5list0EEEvNS0_4typeIvEERT_RT0_i + 78
 16  mongod                              0x0000000108ad6462 _ZN5boost3_bi6bind_tIvPFvPN5mongo13MessagingPortEENS0_5list1INS0_5valueIS4_EEEEEclEv + 92
 17  mongod                              0x0000000108ad648d _ZN5boost6detail11thread_dataINS_3_bi6bind_tIvPFvPN5mongo13MessagingPortEENS2_5list1INS2_5valueIS6_EEEEEEE3runEv + 37
 18  mongod                              0x00000001089883e9 thread_proxy + 169
 19  libsystem_c.dylib                   0x000000010a8db8bf _pthread_start + 335
Fri Aug 31 15:11:22 [conn2] end connection 127.0.0.1:49733 (0 connections now open)
 



 Comments   
Comment by Scott Hernandez (Inactive) [ 02/Oct/13 ]

This has been fixed in the new update code in 2.5.3.

> db.u.findAndModify( { query:{ _id:1 }, update:{ _id:2 }, upsert:true, new:true } );
Wed Oct  2 13:28:01.003 findAndModifyFailed failed: {
	"errmsg" : "exception: The _id field cannot be changed",
	"code" : 16836,
	"ok" : 0
> db.u.find()
>

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