Skip to content

Commit

Permalink
fix(collection): fix error when calling remove with no args (#1657)
Browse files Browse the repository at this point in the history
Calling remove with no arguments resulted in an error b/c
of the lack of options.

Fixes NODE-1287
  • Loading branch information
daprahamian authored Jan 30, 2018
1 parent 3ac3656 commit 4c9b0f8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,9 @@ define.classMethod('removeMany', { callback: true, promise: true });
* @deprecated use deleteOne, deleteMany or bulkWrite
*/
Collection.prototype.remove = function(selector, options, callback) {
if (typeof options === 'function') (callback = options), (options = {});
options = options || {};

// Add ignoreUndfined
if (this.s.options.ignoreUndefined) {
options = shallowClone(options);
Expand Down
34 changes: 34 additions & 0 deletions test/functional/remove_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,38 @@ describe('Remove', function() {
});
}
});

/**
* @ignore
*/
it('should not error on empty remove', {
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
},

// The actual test we wish to run
test: function(done) {
var self = this;
var client = self.configuration.newClient(self.configuration.writeConcernMax(), {
poolSize: 1
});

client.connect(function(err, client) {
var db = client.db(self.configuration.db);
test.equal(null, err);
const collection = db.collection('remove_test');

collection.remove().then(
() => {
client.close();
done();
},
err => {
client.close();
done(err);
}
);
});
}
});
});

0 comments on commit 4c9b0f8

Please sign in to comment.