Skip to content

Commit 4c9b0f8

Browse files
authored
fix(collection): fix error when calling remove with no args (#1657)
Calling remove with no arguments resulted in an error b/c of the lack of options. Fixes NODE-1287
1 parent 3ac3656 commit 4c9b0f8

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/collection.js

+3
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,9 @@ define.classMethod('removeMany', { callback: true, promise: true });
12301230
* @deprecated use deleteOne, deleteMany or bulkWrite
12311231
*/
12321232
Collection.prototype.remove = function(selector, options, callback) {
1233+
if (typeof options === 'function') (callback = options), (options = {});
1234+
options = options || {};
1235+
12331236
// Add ignoreUndfined
12341237
if (this.s.options.ignoreUndefined) {
12351238
options = shallowClone(options);

test/functional/remove_tests.js

+34
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,38 @@ describe('Remove', function() {
153153
});
154154
}
155155
});
156+
157+
/**
158+
* @ignore
159+
*/
160+
it('should not error on empty remove', {
161+
metadata: {
162+
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
163+
},
164+
165+
// The actual test we wish to run
166+
test: function(done) {
167+
var self = this;
168+
var client = self.configuration.newClient(self.configuration.writeConcernMax(), {
169+
poolSize: 1
170+
});
171+
172+
client.connect(function(err, client) {
173+
var db = client.db(self.configuration.db);
174+
test.equal(null, err);
175+
const collection = db.collection('remove_test');
176+
177+
collection.remove().then(
178+
() => {
179+
client.close();
180+
done();
181+
},
182+
err => {
183+
client.close();
184+
done(err);
185+
}
186+
);
187+
});
188+
}
189+
});
156190
});

0 commit comments

Comments
 (0)