[CDRIVER-973] JSON DBRef objects are incorrectly converted to BSON Created: 29/Oct/15  Updated: 08/Dec/15  Resolved: 23/Nov/15

Status: Closed
Project: C Driver
Component/s: json, libbson
Affects Version/s: 1.2.0
Fix Version/s: 1.3.0-rc0

Type: Bug Priority: Major - P3
Reporter: Jeremy Mikola Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by PHPC-474 fromJSON() does not handle DBRef docu... Closed
Related
is related to CDRIVER-1033 dbpointer not handled in bson-json.c Closed

 Description   

Converting a DBRef from JSON to BSON results in an ObjectId type:

{ "dbref": { "$ref": "collection", "$id": { "$oid": "56315a7c6118fd1b920270b1" }}}

Results in:

     0 : 18 00 00 00 07 64 62 72 65 66 00 56 31 5a 7c 61  [.....dbref.V1Z|a]
    10 : 18 fd 1b 92 02 70 b1 00                          [.....p..]

Peaking into bson-json.c revealed that libbson attempts to convert DBRef objects to deprecated DBPointer types. I'm not sure why an ObjectId is being generated, but even the intentional behavior seems incorrect.

DBRef objects should allow any value as their $id (obviously arrays cannot be IDs, but I assume the server only enforces this on documents' _id field value, not DBRefs). Additionally, DBRef objects may contain additional fields (e.g. $db, and any non-$-prefixed fields thereafter). Correct behavior would be to simply convert DBRef objects to embedded documents.



 Comments   
Comment by Githook User [ 23/Nov/15 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-973 parse DBRefs correctly from JSON

A doc containing $ref and $id is called a DBRef but there's no special
BSON format for it. The JSON parser should treat it like any document.
Branch: master
https://github.com/mongodb/libbson/commit/00bddc430cfb62ed29bdb7aa33946578070bc140

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