[SERVER-9790] DBRef string representation should include $db Created: 28/May/13  Updated: 18/Apr/16  Resolved: 06/Jun/14

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: 2.7.2

Type: Improvement Priority: Minor - P4
Reporter: Stephen Lee Assignee: Stephen Lee
Resolution: Done Votes: 2
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-9677 $db values for DBRef datatype does no... Closed
Related
related to SERVER-23786 Server allows insertion and update of... Backlog
related to SERVER-14554 DBRef JS constructor does not accept ... Closed
is related to CDRIVER-457 Allow DBRef object notation for embed... Closed
is related to SERVER-10777 Allow JSON Parser to support addition... Closed
Participants:

 Description   

The string representation of DBRef only shows the $ref and $id but not the $db. This could lead to confusion if the DBRef references a different database.

> db.halloa.find({"name" : "dukur"})
{ "_id" : ObjectId("519e5c065ef254863b9051c6"), "name" : "dukur", "myref" : DBRef("people", "5191cc6684ae75ea07e4ef3b") }
> z=db.halloa.find({"name" : "dukur"}).toArray()[0]
{
    "_id" : ObjectId("519e5c065ef254863b9051c6"),
    "name" : "dukur",
    "myref" : DBRef("people", "5191cc6684ae75ea07e4ef3b")
}
> z.myref.$id
5191cc6684ae75ea07e4ef3b
> z.myref.$ref
people
> z.myref.$db
kamal



 Comments   
Comment by Githook User [ 19/Jul/14 ]

Author:

{u'username': u'benety', u'name': u'Benety Goh', u'email': u'benety@mongodb.com'}

Message: SERVER-9790 SERVER-14554 (v8-3.25) Add this.$db || db.toString() to DBRef string representation
Branch: master
https://github.com/mongodb/mongo/commit/63bca554b175f27451876df5a975f43dc79f55ee

Comment by Githook User [ 06/Jun/14 ]

Author:

{u'username': u'sl33nyc', u'name': u'Stephen Lee', u'email': u'stephen.lee@10gen.com'}

Message: SERVER-9790 Add this.$db || db.toString() to DBRef string representation

Signed-off-by: Benety Goh <benety@mongodb.com>
Branch: master
https://github.com/mongodb/mongo/commit/0cc8d91cb3f1a60d5a80f97ec13660b850b99bc3

Comment by Daniel Pasette (Inactive) [ 19/Feb/14 ]

Will need to also fix the fetch() method on the DBRef object as it doesn't take into account the $db argument.

> DBRef('a',1).fetch
function (){
        assert(this.$ref, "need a ns");
        assert(this.$id, "need an id");
        return db[ this.$ref ].findOne({ _id : this.$id });
    }

Would also want to change the exposed functions to include $db and getDb()

> f.
f.$id                    f.fetch(                 f.getRef(                f.toLocaleString(        f.valueOf(
f.$ref                   f.getCollection(         f.hasOwnProperty(        f.toString(
f.constructor            f.getId(                 f.propertyIsEnumerable(  f.tojson(

Generated at Thu Feb 08 03:21:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.