本文整理匯總了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);
});