06789a6cb7d87038d08dbe4eeffacdfe8ab49571
[aai/esr-gui.git] /
1 /**
2  * A class representation of the BSON DBRef type.
3  *
4  * @class
5  * @param {string} namespace the collection name.
6  * @param {ObjectID} oid the reference ObjectID.
7  * @param {string} [db] optional db name, if omitted the reference is local to the current db.
8  * @return {DBRef}
9  */
10 function DBRef(namespace, oid, db) {
11   if(!(this instanceof DBRef)) return new DBRef(namespace, oid, db);
12   
13   this._bsontype = 'DBRef';
14   this.namespace = namespace;
15   this.oid = oid;
16   this.db = db;
17 };
18
19 /**
20  * @ignore
21  * @api private
22  */
23 DBRef.prototype.toJSON = function() {
24   return {
25     '$ref':this.namespace,
26     '$id':this.oid,
27     '$db':this.db == null ? '' : this.db
28   };
29 }
30
31 module.exports = DBRef;
32 module.exports.DBRef = DBRef;