How to use the mongodb.DBRef function in mongodb

To help you get started, we’ve selected a few mongodb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mongo-express / mongo-express / test / lib / bsonSpec.js View on Github external
it('should convert DBRef to string', function () {
      const test = {
        ref: mongodb.DBRef('coll', mongodb.ObjectId('57b80f922128ccef64333288'), ''),
        ref2: mongodb.DBRef('coll', mongodb.ObjectId('57b80f922128ccef64333288'), 'db'),
      };
      const result = bson.toString(test);
      const expected = `{\n    ref: DBRef('coll', '57b80f922128ccef64333288', ''),\n    ref2: DBRef('coll', '57b80f922128ccef64333288', 'db')\n}`;
      expect(result).to.eql(expected);
    });
github mongo-express / mongo-express / test / lib / bsonSpec.js View on Github external
it('should convert DBRef to string', function () {
      const test = {
        ref: mongodb.DBRef('coll', mongodb.ObjectId('57b80f922128ccef64333288'), ''),
        ref2: mongodb.DBRef('coll', mongodb.ObjectId('57b80f922128ccef64333288'), 'db'),
      };
      const result = bson.toString(test);
      const expected = `{\n    ref: DBRef('coll', '57b80f922128ccef64333288', ''),\n    ref2: DBRef('coll', '57b80f922128ccef64333288', 'db')\n}`;
      expect(result).to.eql(expected);
    });
github apollo-model / apollo-model / packages / core / src / modules / directives / relation.js View on Github external
if (this.isAbstract) {
        collection = selector.mmCollectionName;
        delete selector.mmCollectionName;
      }
      let ids = await this._distinctQuery({
        collection,
        selector,
        context,
      });
      if (ids.length === 0) {
        throw new UserInputError(
          `No records found for selector - ${JSON.stringify(selector)}`
        );
      }
      let id = this.isAbstract
        ? new DBRef(collection, _.head(ids))
        : _.head(ids);
      return { [storeField]: id };
    } else if (input.create) {
      ////Create
      let doc = input.create;
      if (this.isAbstract) {
        let { mmCollectionName: collection, ...doc } = doc;
      }
      let id = await this._insertOneQuery({
        doc,
        collection,
        context,
      });
      id = this.isAbstract ? new DBRef(collection, id) : id;
      return { [storeField]: id };
    } else if (input.disconnect) {
github apollo-model / apollo-model / packages / core / src / modules / directives / relation.js View on Github external
let id = this.isAbstract
        ? new DBRef(collection, _.head(ids))
        : _.head(ids);
      return { [storeField]: id };
    } else if (input.create) {
      ////Create
      let doc = input.create;
      if (this.isAbstract) {
        let { mmCollectionName: collection, ...doc } = doc;
      }
      let id = await this._insertOneQuery({
        doc,
        collection,
        context,
      });
      id = this.isAbstract ? new DBRef(collection, id) : id;
      return { [storeField]: id };
    } else if (input.disconnect) {
      ////Disconnect
      return {
        [storeField]: { $mmUnset: 1 },
      };
    } else if (input.delete) {
      collection = this.isAbstract ? input.delete.mmCollectionName : collection;
      return {
        [storeField]: {
          $mmDeleteSingleRelation: { collection, relationField },
        },
      };
    }
  };
github apollo-model / apollo-model / lib / directives / relation.js View on Github external
////Create
          let doc = input.create;

          if (this.isAbstract) {
            let {
              mmCollectionName: collection,
              ...doc
            } = doc;
          }

          let id = await this._insertOneQuery({
            doc,
            collection,
            context
          });
          id = this.isAbstract ? new _mongodb.DBRef(collection, id) : id;
          return {
            [storeField]: id
          };
        } else if (input.disconnect) {
          ////Disconnect
          return {
            [storeField]: {
              $mmUnset: 1
            }
          };
        } else if (input.delete) {
          collection = this.isAbstract ? input.delete.mmCollectionName : collection;
          return {
            [storeField]: {
              $mmDeleteSingleRelation: {
                collection,