本文整理汇总了TypeScript中mongodb.ObjectID.toHexString方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ObjectID.toHexString方法的具体用法?TypeScript ObjectID.toHexString怎么用?TypeScript ObjectID.toHexString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongodb.ObjectID
的用法示例。
在下文中一共展示了ObjectID.toHexString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Error
collection.replaceOne({ _id: id }, entity, (err: WriteError, result: UpdateWriteOpResult) => {
if (err) {
throw new Error(err.errmsg);
}
console.log(result.toString());
entity._id = id.toHexString();
subject.next(entity);
subject.complete();
});
示例2: function
me.db.collection(collection).findOneAndUpdate(query, {$set: userx}, {projection: {_id: 1}}, function (err, r) {
if (err) throw err;
// case 3 : user doesn't exist
if (r.value === null) return updateUserInfo(me.db, themtid, userx, callback);
// user exist
var ide_mtid:mongodb.ObjectID = r.value._id;
// check for case 1
if (themtid.toHexString() === ide_mtid.toHexString()) return updateUserInfo(me.db, themtid, userx, callback);
// case 2
// add to mapping collection
me.db.collection(collectionmapping).insertOne({
anomtid: themtid,
idemtid: ide_mtid,
ctime: new Date()
}, function (err) {
if (err) throw err;
});
//convert all ano-mtid to ide-mtid
var query = {};
var update = {};
query[ids._mtid] = themtid;
update[ids._mtid] = ide_mtid;
me.db.collection(collection).updateMany(query, {$set: update}, function (err) {
if (err) throw err;
});
// merge and delete ano-mtid record IF EXISTED
me.db.collection(collection).find({_id: themtid}).limit(1).toArray(function (err, r) {
if (err) throw err;
if (r.length === 0) return;
var olduser = r[0];
me.mergeInfo(olduser, userx, ids);
me.db.collection(collection).deleteOne({_id: themtid}, function (err) {
if (err) throw err;
});
return updateUserInfo(me.db, ide_mtid, userx, callback);
});
});
示例3: it
it("should correctly diff ObjectIDs", function () {
let oldID = new MongoDB.ObjectID();
let newID = MongoDB.ObjectID.createFromHexString(oldID.toHexString());
let oldObject = { _id: oldID };
let newObject = { _id: newID };
let expectedDiff = {
};
chai.expect(Omnom.diff(oldObject, newObject)).to.exist.and.be.eql(expectedDiff);
newID = new MongoDB.ObjectID();
oldObject = { _id: oldID };
newObject = { _id: newID };
expectedDiff = {
$set: { _id: newID }
};
chai.expect(Omnom.diff(oldObject, newObject)).to.exist.and.be.eql(expectedDiff);
});