summaryrefslogtreecommitdiff
path: root/node_modules/mongoose/lib/drivers/node-mongodb-native/objectid.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2012-09-24 16:22:07 -0400
committerJules Laplace <jules@okfoc.us>2012-09-24 16:22:07 -0400
commit686106d544ecc3b6ffd4db2b665d3bc879a58d8c (patch)
treea5b5e50237cef70e12f0745371896e96f5f6d578 /node_modules/mongoose/lib/drivers/node-mongodb-native/objectid.js
ok
Diffstat (limited to 'node_modules/mongoose/lib/drivers/node-mongodb-native/objectid.js')
-rw-r--r--node_modules/mongoose/lib/drivers/node-mongodb-native/objectid.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/node_modules/mongoose/lib/drivers/node-mongodb-native/objectid.js b/node_modules/mongoose/lib/drivers/node-mongodb-native/objectid.js
new file mode 100644
index 0000000..ee6d598
--- /dev/null
+++ b/node_modules/mongoose/lib/drivers/node-mongodb-native/objectid.js
@@ -0,0 +1,43 @@
+
+/**
+ * Module dependencies.
+ */
+
+var ObjectId = require('mongodb').BSONPure.ObjectID;
+
+/**
+ * Constructor export
+ *
+ * @api private
+ */
+
+var ObjectIdToString = ObjectId.toString.bind(ObjectId);
+
+module.exports = exports = ObjectId;
+/**
+ * Creates an ObjectID for this driver
+ *
+ * @param {Object} hex string or ObjectId
+ * @api private
+ */
+
+exports.fromString = function(str){
+ // patch native driver bug in V0.9.6.4
+ if (!('string' === typeof str && 24 === str.length)) {
+ throw new Error("Invalid ObjectId");
+ }
+
+ return ObjectId.createFromHexString(str);
+};
+
+/**
+ * Gets an ObjectId and converts it to string.
+ *
+ * @param {ObjectId} -native objectid
+ * @api private
+ */
+
+exports.toString = function(oid){
+ if (!arguments.length) return ObjectIdToString();
+ return oid.toHexString();
+};