[SERVER-7072] Improve error reporting message on invalid input to findandmodify Created: 19/Sep/12  Updated: 10/Dec/14  Resolved: 10/Nov/14

Status: Closed
Project: Core Server
Component/s: Internal Code, Usability, Write Ops
Affects Version/s: 2.0.7, 2.2.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Koen Serry Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: erorr, findandmodify
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-6399 Refactor update() code Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

> db.c.update({}, {$set:{a:1}, inc:{foo:1}})
fn[0] == '$'
> db.c.update({}, {set:{a:1}, $inc:{foo:1}})
Wed Sep 19 08:50:00 uncaught exception: field names cannot start with $ [$inc]
 
> db.c.runCommand("findandmodify", {query: { }, update: { $inc: { a:1 }, set: { f:1} } })
{
	...,
	"errmsg" : "exception: assertion src/mongo/db/ops/update_internal.h:253",
	"code" : 0,
	"ok" : 0
}
> db.c.runCommand("findandmodify", {query: { }, update: { inc: { a:1 }, $set: { f:1} } })
{
	...,
	"errmsg" : "exception: Modifiers and non-modifiers cannot be mixed",
	"code" : 10154,
	"ok" : 0
}
 

Wed Sep 19 08:49:29 [conn2]  aboutme_config.c Assertion failure fn[0] == '$' src/mongo/db/ops/update_internal.h 253
0x10037637b 0x1000b0196 0x10044c913 0x10045f3d0 0x100463986 0x100643f29 0x10064a391 0x100018681 0x10019302c 0x1005a7823 0x7fff817fdfd6 0x7fff817fde89 
 0   mongod                              0x000000010037637b _ZN5mongo15printStackTraceERSo + 43
 1   mongod                              0x00000001000b0196 _ZN5mongo12verifyFailedEPKcS1_j + 310
 2   mongod                              0x000000010044c913 _ZN5mongo6ModSetC2ERKNS_7BSONObjERKSt3setISsSt4lessISsESaISsEEPS9_ + 5699
 3   mongod                              0x000000010045f3d0 _ZN5mongo14_updateObjectsEbPKcRKNS_7BSONObjES4_bbbRNS_7OpDebugEPNS_11RemoveSaverEbRKNS_24QueryPlanSelectionPolicyE + 880
 4   mongod                              0x0000000100463986 _ZN5mongo13updateObjectsEPKcRKNS_7BSONObjES4_bbbRNS_7OpDebugEbRKNS_24QueryPlanSelectionPolicyE + 294
 5   mongod                              0x0000000100643f29 _ZN5mongo14receivedUpdateERNS_7MessageERNS_5CurOpE + 1273
 6   mongod                              0x000000010064a391 _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE + 4721
 7   mongod                              0x0000000100018681 _ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE + 257
 8   mongod                              0x000000010019302c _ZN5mongo3pms9threadRunEPNS_13MessagingPortE + 1084
 9   mongod                              0x00000001005a7823 thread_proxy + 163
 10  libSystem.B.dylib                   0x00007fff817fdfd6 _pthread_start + 331
 11  libSystem.B.dylib                   0x00007fff817fde89 thread_start + 13
Wed Sep 19 08:49:29 [conn2] update aboutme_config.c update: { $set: { a: 1.0 }, inc: { foo: 1.0 } } keyUpdates:0 exception: assertion src/mongo/db/ops/update_internal.h:253 locks(micros) w:392366 391ms
Wed Sep 19 07:55:30 [conn3984] run command test.$cmd { findandmodify: "mycollection", query: { _id: ObjectId('50595e523372fb9c51bc3e55') }, update: { $addToSet: { available: ObjectId('50595e523372fb9c51bc3e56') }, set: { lastAvailable: new Date(1348034130332) } } }
Wed Sep 19 07:55:30 [conn3984]  test.mycollection Assertion failure fn[0] == '$' src/mongo/db/ops/update_internal.h 253
0x10037637b 0x1000b0196 0x10044c913 0x10045f3d0 0x100463986 0x100260a52 0x1002628f4 0x100263eec 0x1003a51d6 0x1003a6a52 0x1003a7a01 0x10008126b 0x100085399 0x1006464c9 0x1006494d6 0x100018681 0x10019302c 0x1005a7823 0x7fff8f1a9782 0x7fff8f1961c1 
 0   mongod                              0x000000010037637b _ZN5mongo15printStackTraceERSo + 43
 1   mongod                              0x00000001000b0196 _ZN5mongo12verifyFailedEPKcS1_j + 310
 2   mongod                              0x000000010044c913 _ZN5mongo6ModSetC2ERKNS_7BSONObjERKSt3setISsSt4lessISsESaISsEEPS9_ + 5699
 3   mongod                              0x000000010045f3d0 _ZN5mongo14_updateObjectsEbPKcRKNS_7BSONObjES4_bbbRNS_7OpDebugEPNS_11RemoveSaverEbRKNS_24QueryPlanSelectionPolicyE + 880
 4   mongod                              0x0000000100463986 _ZN5mongo13updateObjectsEPKcRKNS_7BSONObjES4_bbbRNS_7OpDebugEbRKNS_24QueryPlanSelectionPolicyE + 294
 5   mongod                              0x0000000100260a52 _ZN5mongo16CmdFindAndModify17runNoDirectClientERKSsRKNS_7BSONObjES5_S5_bbbRNS_14BSONObjBuilderE + 546
 6   mongod                              0x00000001002628f4 _ZN5mongo16CmdFindAndModify17runNoDirectClientERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 2212
 7   mongod                              0x0000000100263eec _ZN5mongo16CmdFindAndModify3runERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 2860
 8   mongod                              0x00000001003a51d6 _ZN5mongo12_execCommandEPNS_7CommandERKSsRNS_7BSONObjEiRNS_14BSONObjBuilderEb + 86
 9   mongod                              0x00000001003a6a52 _ZN5mongo11execCommandEPNS_7CommandERNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb + 5058
 10  mongod                              0x00000001003a7a01 _ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 1697
 11  mongod                              0x000000010008126b _ZN5mongo11runCommandsEPKcRNS_7BSONObjERNS_5CurOpERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 59
 12  mongod                              0x0000000100085399 _ZN5mongo8runQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_ + 4345
 13  mongod                              0x00000001006464c9 _ZN5mongoL13receivedQueryERNS_6ClientERNS_10DbResponseERNS_7MessageE + 393
 14  mongod                              0x00000001006494d6 _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE + 950
 15  mongod                              0x0000000100018681 _ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE + 257
 16  mongod                              0x000000010019302c _ZN5mongo3pms9threadRunEPNS_13MessagingPortE + 1084
 17  mongod                              0x00000001005a7823 thread_proxy + 163
 18  libsystem_c.dylib                   0x00007fff8f1a9782 _pthread_start + 327
 19  libsystem_c.dylib                   0x00007fff8f1961c1 thread_start + 13



 Comments   
Comment by J Rassi [ 10/Nov/14 ]

As of 2.6.0, the server reports a friendlier error (and does not log a stack trace):

> db.c.runCommand("findandmodify", {query: { }, update: { $inc: { a:1 }, set: { f:1} } })
{
	"value" : {
		"_id" : ObjectId("5461407238e480a427a8a197")
	},
	"errmsg" : "exception: Unknown modifier: set",
	"code" : 9,
	"ok" : 0
}
>

Resolving as dup of SERVER-6399.

Comment by Scott Hernandez (Inactive) [ 19/Sep/12 ]

Yes, we should return a better error message and handle the assertion better internally. If you do this with update you get back a better error message.

Thanks for the report.

Comment by Koen Serry [ 19/Sep/12 ]

Yep that was it, thanks. Strange to see an assertion error though.

Comment by Scott Hernandez (Inactive) [ 19/Sep/12 ]

Looks like your set operation is missing the $ prefix. Can you try fixing that and running again?

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