Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-973

JSON DBRef objects are incorrectly converted to BSON

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.3.0-rc0
    • Affects Version/s: 1.2.0
    • Component/s: json, libbson
    • None

      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.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: