[JAVA-2644] Improve BasicDBObject.parse to support DBRefs with $db field Created: 20/Oct/17  Updated: 29/Oct/23  Resolved: 30/Jan/18

Status: Closed
Project: Java Driver
Component/s: Codecs
Affects Version/s: None
Fix Version/s: 3.7.0

Type: Bug Priority: Minor - P4
Reporter: Jonathan Balsano Assignee: Ross Lawley
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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



 Comments   
Comment by Githook User [ 30/Jan/18 ]

Author:

{'email': 'ross.lawley@gmail.com', 'name': 'Ross Lawley', 'username': 'rozza'}

Message: Fixed DBRef json support in DBObject

JAVA-2644
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/ed495e28bfaa2d61846a0286decf8faee603df76

Generated at Thu Feb 08 08:57:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.