[SERVER-10777] Allow JSON Parser to support additional fields when parsing DBRefs Created: 16/Sep/13  Updated: 07/Apr/17  Resolved: 07/Apr/17

Status: Closed
Project: Core Server
Component/s: Internal Code, Tools
Affects Version/s: 2.4.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Andor Tóth Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Won't Fix Votes: 1
Labels: community-team, dbref, json, mongoimport, parser
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-10779 JSON Parser Needs to Support the DBRe... Closed
Documented
is documented by DOCS-9543 Docs for SERVER-10777: Allow JSON Par... Closed
Related
related to SERVER-23786 Server allows insertion and update of... Backlog
related to SERVER-9790 DBRef string representation should in... Closed
related to SERVER-12695 Support fields within DBRef Closed
is related to CDRIVER-457 Allow DBRef object notation for embed... Closed
is related to SERVER-12263 Support $elemMatch with DBRefs that m... Closed
is related to SERVER-612 Allow Arbitrary Properties on DBRefs Closed
Operating System: ALL
Participants:

 Description   

This works:

$ echo '{ "_id" : { "$oid" : "5062d20310db79406d000059" }, "parent" : { "$ref" : "box", "$id" : { "$oid" : "5062d1d810db799135000005" } } }' | mongoimport -d test -c testcoll 
connected to: 127.0.0.1
Mon Sep 16 11:26:01.811 imported 1 objects

This does not:

$ echo '{ "_id" : { "$oid" : "5062d20310db79406d000059" }, "parent" : { "$ref" : "box", "$id" : { "$oid" : "5062d1d810db799135000005" }, "_doctrine_class_name" : "Box" } }' | mongoimport -d test -c testcoll 
connected to: 127.0.0.1
Mon Sep 16 11:26:29.705 exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Expecting '}' or ',': offset:127
Mon Sep 16 11:26:29.705 
Mon Sep 16 11:26:29.705 check 0 0
Mon Sep 16 11:26:29.705 imported 0 objects
Mon Sep 16 11:26:29.705 ERROR: encountered 1 error(s)

Notice the extra "_doctrine_class_name" field in the DBRef.
If I use the MongoDB 2.2 mongoimport, then it works.

There's been an issue with same summary for 1.3, but with different content.



 Comments   
Comment by Andrew Morrow (Inactive) [ 07/Apr/17 ]

While this is a real bug, DBRef support is deprecated, so we are not planning to make improvements or bug fixes related to it.

Comment by Shaun Verch [ 10/Jun/14 ]

This can be fixed by modifying the "dbRefObject" function to parse additional fields after it encounters the "$db" field: https://github.com/mongodb/mongo/blob/r2.7.1/src/mongo/db/json.cpp#L563.

The similar looking "dbRef" function is for parsing the "DBRef()" shell-style constructor, but should not be necessary to change for this ticket: https://github.com/mongodb/mongo/blob/r2.7.1/src/mongo/db/json.cpp#L829

Note that the "DBRef" object that gets parsed by the JSON parser turns into a normal object that has the "$dbref" field rather than the "DBRef" BSON type. See https://github.com/mongodb/mongo/blob/r2.7.1/src/mongo/dbtests/jsontests.cpp#L1023 for this behavior.

For additional context, the "DBRef" constructor in the shell works the same way, and the "DBPointer" constructor makes the actual "DBRef" type. See https://github.com/mongodb/mongo/blob/r2.7.1/src/mongo/dbtests/jstests.cpp#L1076 for this behavior.

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