Permalink
Browse files

Implemented Collection.remove()

  • Loading branch information...
1 parent c6ea6d5 commit e26c8d7cf0bfa7b7f885c62086a18fee12968d06 @sergi committed May 28, 2010
Showing with 17 additions and 3 deletions.
  1. +4 −1 lib/collection.js
  2. +2 −2 lib/mongosupport.js
  3. +11 −0 tests/DBCollectionTest.js
View
@@ -168,10 +168,13 @@ Collection.prototype = {
criteria = { "_id": criteria };
}
this.collection.update(Support.createBDObject(criteria), Support.createBDObject(obj));
- },
+ },
resetIndexCache: function() {
this._indexCache = {};
this.collection.resetIndexCache();
+ },
+ remove: function(obj) {
+ this.collection.remove(Support.createBDObject(obj));
}
}
View
@@ -13,8 +13,8 @@ var MongoSupport = {
return o;
},
createBDObject: function(obj, ensureId) {
- var o = new Packages.com.mongodb.BasicDBObject(ensureId ? this.ensureId(obj || {}) : obj || {});
- return o
+ obj = obj || {};
+ return new Packages.com.mongodb.BasicDBObject(ensureId ? this.ensureId(obj) : obj);
},
extend: function( dst , src , deep ) {
for (var k in src){
View
@@ -62,6 +62,17 @@ exports.testSave = function() {
assert.isTrue(docId == id, "17");
assert.isTrue(Packages.com.mongodb.ObjectId.isValid(id));
}
+exports.testRemove = function() {
+ var c = _db.getCollection( "test" );
+ c.drop();
+
+ c.insert({"_id": 123, "x": 100});
+ var obj = (c.findOne());
+ assert.isTrue(obj != null, "18");
+ c.remove({"x": 100});
+ obj = c.findOne();
+ assert.isTrue(obj == null, "19");
+}
if (require.main == module.id)
require("os").exit(require("test/runner").run(exports));

0 comments on commit e26c8d7

Please sign in to comment.