New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SERVER-9790 Add this.$db || db.toString() to DBRef string representation #638
Conversation
@@ -393,6 +398,10 @@ if (typeof(DBRef) != "undefined"){ | |||
return this.toString(); | |||
} | |||
|
|||
DBRef.prototype.getDb = function(){ | |||
return this.$db || db.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not default to current DB if undefined.
There should also be jstests for this. See: |
Removed default |
|
||
db.getMongo().getDB("otherdb").dropDatabase(); | ||
var objid = new ObjectId(); | ||
db.getMongo().getDB("otherdb").getCollection("othercoll").insert({_id:objid, field:"value"}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using db.getSiblingDB("otherdb") instead of getMongo().getDB(). This is the convention in most of the JS tests.
@benety, one more pass please. |
LGTM. @scotthernandez ? |
} | ||
|
||
DBRef.prototype.tojson = function(indent){ | ||
return this.toString(); | ||
} | ||
|
||
DBRef.prototype.getDb = function(){ | ||
return this.$db || null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably more correct to replace null with undefined, to indicate it is not set.
Or return the current db. If that is done then fetch can be changed to:
return db.getSiblingDB(getDb()).getCollection(getCollection()).find({ _id : this.$id }):
LGTM, aside from my previous note. |
@@ -386,13 +386,18 @@ if (typeof(DBRef) != "undefined"){ | |||
DBRef.prototype.fetch = function(){ | |||
assert(this.$ref, "need a ns"); | |||
assert(this.$id, "need an id"); | |||
return db[ this.$ref ].findOne({ _id : this.$id }); | |||
var coll = this.$db ? db.getSiblingDB(this.$db).getCollection(this.$ref) : db[this.$ref]; | |||
return coll.findOne({ _id : this.$id }): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
colon at end of line?
Whoops! Typo fixed. |
Thanks. Running patch through CI now. |
Hi Stephen, This pull request has been merged in commit 0cc8d91. Thank you for contributing! |
Use atomic operations to swap new page structures into place.
If the optional
$db
argument is specified in the $DBRef, prepend it before the collection name. Otherwise, prepend the current database before the collection name.