Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2644

Improve BasicDBObject.parse to support DBRefs with $db field

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.7.0
    • Affects Version/s: None
    • Component/s: Codecs
    • Labels:
      None

      Currently, if you call BasicDBObject.parse on a json string like the following:

      { myDbRef: {
          $ref: "collection",
          $id: { $oid: "59ce7963a43f254534602da9" },
          $db: "myDB"
      }
      

      The Java Driver will return an object that contains the "$ref" and "$id" as supplied, but drops the "$db". The cause for this seems to be these lines: https://github.com/mongodb/mongo-java-driver/blob/master/driver/src/main/com/mongodb/DBObjectCodec.java#L359-L363 which discard the "$db" value and use the constructor for DBRef that doesn't include $db.

      The verifyForDBRef function should be modified to use both constructors based on whether or not "$db" is available

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            jonathan.balsano@mongodb.com Jonathan Balsano
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: