[SERVER-3231] Upsert with $db is failing Created: 09/Jun/11  Updated: 12/Jul/16  Resolved: 12/Dec/13

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

Type: Bug Priority: Major - P3
Reporter: John Crenshaw Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-7557 Update doesn't support "$"s in the fi... Closed
Related
related to SERVER-14244 Additional tests for setting fields w... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

A similar problem was reported a while back as SERVER-627. The fix covered $id and $ref cases, but didn't fix it for references containing a $db value. If you check https://github.com/mongodb/mongo/blame/master/db/jsobj.cpp @ line 847 and 847 you'll see that it checks for $ref and $id, but not for $db. This is causing certain upserts to fail with "not okForStorage". Removing the $db value from the references before attempting to upsert avoids the problem, so I'm using that as a workaround for now.

Also, it took me ages to riddle out what was causing this. Is there any way you could give more specific information about the invalid syntax? Something like "okForStorage failed with message: key '$db' is not allowed. Check your record and try again." would have saved an incredible amount of time. "not okForStorage" is just cryptic and unhelpful.



 Comments   
Comment by Scott Hernandez (Inactive) [ 12/Dec/13 ]

Please create a new issue and do not re-open this since it has already been committed and released.

Comment by Jonathan Abrahams [ 12/Dec/13 ]

// Test that '$id', '$db', and '$ref' are acceptable field names in
// the correct case (ie, subdoc) but not otherwise.
// SERVER-3231
coll.update(

{ n: 0 }

, { $set: { $id: 1, $db: 1, $ref: 1 }});
var gle = db.runCommand(

{ getLastError: 1 }

);
assert(gle.err != null, 'gleObj: ' + tojson(gle));
coll.update(

{ n: 0 }

,

{ n: 0 }

);

coll.update(

{ n: 0 }

, { $set: { 'x.$id': 1, 'x.$db': 1, 'x.$ref': 1 }});
var gle = db.runCommand(

{ getLastError: 1 }

);
assert(gle.err == null, 'gleObj: ' + tojson(gle));
coll.update(

{ n: 0 }

,

{ n: 0 }

);

Assert thrown from second update:

2013-12-12T12:39:01.485-0500 assert failed : gleObj: {
"err" : "The DBRef $db field must be a String, not a NumberDouble",
"code" : 55,
"n" : 0,
"connectionId" : 171,
"ok" : 1
} at src/mongo/shell/assert.js:7

Comment by Scott Hernandez (Inactive) [ 27/Jul/13 ]

fixed in SERVER-7557

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