Skip to content

Commit

Permalink
add SkinDb.toId, SkinCollection.id is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
guileen committed Dec 2, 2011
1 parent a3c75fd commit 2b4e531
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/mongoskin/collection.js
Expand Up @@ -174,11 +174,11 @@ SkinCollection.prototype.findEach = function() {
this._find.apply(this, args);
};

/**
* @deprecated use SkinDb.id instead
*/
SkinCollection.prototype.id = function(hex) {
if(hex instanceof this.ObjectID) {
return hex;
}
return this.skinDb.db.bson_serializer.ObjectID.createFromHexString(hex);
return this.skinDb.toId(hex);
};

/**
Expand All @@ -191,7 +191,7 @@ SkinCollection.prototype.id = function(hex) {
*/
SkinCollection.prototype.findById = function() {
var args = __slice.call(arguments);
args[0] = {_id: this.id(args[0])};
args[0] = {_id: this.skinDb.toId(args[0])};
this.findOne.apply(this, args);
};

Expand All @@ -200,7 +200,7 @@ SkinCollection.prototype.findById = function() {
*/
SkinCollection.prototype.updateById = function() {
var args = __slice.call(arguments);
args[0] = {_id: this.id(args[0])};
args[0] = {_id: this.skinDb.toId(args[0])};
this.update.apply(this, args);
};

Expand All @@ -209,7 +209,7 @@ SkinCollection.prototype.updateById = function() {
*/
SkinCollection.prototype.removeById = function() {
var args = __slice.call(arguments);
args[0] = {_id: this.id(args[0])};
args[0] = {_id: this.skinDb.toId(args[0])};
this.remove.apply(this, args);
};

Expand Down
8 changes: 8 additions & 0 deletions lib/mongoskin/db.js
Expand Up @@ -60,6 +60,14 @@ var SkinDb = exports.SkinDb = function(db, username, password) {
this.ObjectID = db.bson_serializer.ObjectID;
};

SkinDb.prototype.toId = function(hex) {
if(hex instanceof this.ObjectID) {
return hex;
}
return this.ObjectID.createFromHexString(hex);
};


/**
* retrieve native_db
*
Expand Down

0 comments on commit 2b4e531

Please sign in to comment.