1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 1 1 1 31 7 24 6 18 1 2 | var mongodb = require('mongodb'); var ObjectID = mongodb.ObjectID; /** * Convert to ObjectID. * * @param {String} hex * @return {ObjectID} */ exports.toObjectID = function (hex) { if (hex instanceof ObjectID) { return hex; } if (!hex || hex.length !== 24) { return hex; } return ObjectID.createFromHexString(hex); }; exports.isObjectID = function (idstr) { return ObjectID.isValid(idstr); }; |