Skip to content

Commit

Permalink
fix(collection): fix error when calling remove with no args
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 committed Jan 30, 2018
1 parent 3ac3656 commit b85d0ef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,8 @@ Collection.prototype.remove = function(selector, options, callback) {
options.ignoreUndefined = this.s.options.ignoreUndefined;
}

options = options || {};

return executeOperation(this.s.topology, removeDocuments, [this, selector, options, callback]);
};

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 b85d0ef

Please sign in to comment.