/node_modules/mongodb/node_modules/bson/lib/bson/db_ref.js

https://bitbucket.org/gagginaspinnata/todo-app-with-angularjs · JavaScript · 33 lines · 17 code · 3 blank · 13 comment · 3 complexity · ae5951f4a59467d96a091e41e342a1de MD5 · raw file

  1. /**
  2. * A class representation of the BSON DBRef type.
  3. *
  4. * @class Represents the BSON DBRef type.
  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. this._bsontype = 'DBRef';
  13. this.namespace = namespace;
  14. this.oid = oid;
  15. this.db = db;
  16. };
  17. /**
  18. * @ignore
  19. * @api private
  20. */
  21. DBRef.prototype.toJSON = function() {
  22. return {
  23. '$ref':this.namespace,
  24. '$id':this.oid,
  25. '$db':this.db == null ? '' : this.db
  26. };
  27. }
  28. if(typeof window === 'undefined') {
  29. exports.DBRef = DBRef;
  30. }