Skip to content

Commit

Permalink
no more normalizing ids
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Sep 23, 2011
1 parent d419919 commit f703899
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@ var common = require('common');

var noop = function() {};

var normalizeId = function() {
var createObjectId = function() {
if (!mongo.BSONNative || !mongo.BSONNative.ObjectID) {
return function(args) {
if (args[0] && typeof args[0] === 'object' && typeof args[0]._id === 'string') {
args[0]._id = mongo.BSONPure.ObjectID.createFromHexString(args[0]._id);
}
return args;
return function(id) {
return mongo.BSONPure.ObjectID.createFromHexString(id);
};
}
return function(args) {
if (args[0] && typeof args[0] === 'object' && typeof args[0]._id === 'string') {
args[0]._id = new mongo.BSONNative.ObjectID(args[0]._id);
}
return args;
return function(id) {
return new mongo.BSONNative.ObjectID(id);
};
}();
var parse = function(options) {
Expand Down Expand Up @@ -87,7 +81,7 @@ var Collection = function(oncollection) {
};

Collection.prototype.find = function() {
var args = normalizeId(Array.prototype.slice.call(arguments));
var args = Array.prototype.slice.call(arguments);
var oncursor = common.future();
var oncollection = this._oncollection;

Expand Down Expand Up @@ -134,7 +128,6 @@ Collection.prototype.remove = function() {
};

Collection.prototype._exec = function(name, args) {
var args = normalizeId(args);
var callback = typeof args[args.length-1] === 'function' ? args[args.length-1] : noop;

this._oncollection.get(common.fork(callback, function(col) {
Expand All @@ -150,6 +143,8 @@ Object.keys(mongo.Collection.prototype).forEach(function(name) { // we just wann
}
});

exports.ObjectId = createObjectId;

exports.connect = function(url, collections) {
url = parse(url);

Expand Down Expand Up @@ -189,6 +184,7 @@ exports.connect = function(url, collections) {
}
], ondb.put);

that.ObjectId = createObjectId;
that.collection = function(name) {
var oncollection = common.future();

Expand Down

0 comments on commit f703899

Please sign in to comment.