You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
660 B

  1. /*!
  2. * [node-mongodb-native](https://github.com/mongodb/node-mongodb-native) ObjectId
  3. * @constructor NodeMongoDbObjectId
  4. * @see ObjectId
  5. */
  6. var ObjectId = require('mongodb').BSONPure.ObjectID;
  7. /*!
  8. * ignore
  9. */
  10. var ObjectIdToString = ObjectId.toString.bind(ObjectId);
  11. module.exports = exports = ObjectId;
  12. ObjectId.fromString = function(str){
  13. // patch native driver bug in V0.9.6.4
  14. if (!('string' === typeof str && 24 === str.length)) {
  15. throw new Error("Invalid ObjectId");
  16. }
  17. return ObjectId.createFromHexString(str);
  18. };
  19. ObjectId.toString = function(oid){
  20. if (!arguments.length) return ObjectIdToString();
  21. return oid.toHexString();
  22. };