Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
});
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);
});
}).then(id => [new _mongodb.DBRef(coll, id)]);
}
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) {
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 },
},
};
}
};
}).then(ids => ids.map(id => new DBRef(collection, id)))
)
value.map(id => new DBRef(this._params.collectionName, id))
);
////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,