[CDRIVER-457] Allow DBRef object notation for embedded documents Created: 05/Nov/14  Updated: 03/May/17  Resolved: 06/Nov/14

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 1.0.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jeremy Mikola Assignee: Mira Carey
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-10777 Allow JSON Parser to support addition... Closed
related to SERVER-612 Allow Arbitrary Properties on DBRefs Closed
related to SERVER-9790 DBRef string representation should in... Closed

 Description   

The C driver currently considers DBRef objects invalid due to $-prefixing of their $ref, $id, and optional $db field names. All of the following embedded document values should past validation:

{ "$ref": <string>, "$id": <anything> }
{ "$ref": <string>, "$id": <anything>, "$db": <string> }
{ "$ref": <string>, "$id": <anything>, "foo": <anything> }
{ "$ref": <string>, "$id": <anything>, "$db": <string>, "foo": <anything> }

The last two examples may appear strange, but because DBRefs are simply embedded documents, they are permitted to contain additional fields (without $ prefixes, of course). Various ODMs take advantage of this to store additional metadata about references, such as the referenced document's class name.

So, the general rule about DBRefs is:

  • They're embedded objects. A top-level document cannot be a DBRef, even if _id was to appear after $ref and $id in the BSON document field sequence.
  • They require $ref and $id as the first and second fields, respectively.
  • An optional $db field is permitted only as the third field.
  • Additional fields may appear in after $id (if there is no $db) or $db, but they cannot have $ prefixes.

As a result of DBRef object notation not being valid (due to $ prefixes on its field names), users may be wrongfully encouraged to create DBPointer BSON types, which have been deprecated for many years.



 Comments   
Comment by Mira Carey [ 06/Nov/14 ]

https://github.com/mongodb/libbson/pull/109

Comment by Jeremy Mikola [ 05/Nov/14 ]

With SERVER-9790, MongoDB 2.8 will now render the $db value in the shell; however, additional fields are still not rendered (I believe that is being tracked by SERVER-10777).

Comment by Jeremy Mikola [ 05/Nov/14 ]

See PHP-1262 and related discussion for how this issue affected the MongoHub OSX application: https://github.com/jeromelebel/MongoHub-Mac/issues/148

Generated at Wed Feb 07 21:09:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.