Skip to content

Commit 402db1a

Browse files
committed
fix(model): support passing options to Model.remove()
Fix #8211
1 parent 7a20276 commit 402db1a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/model.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,8 @@ Model.prototype.$__where = function _where(where) {
874874
* assert.ok(err)
875875
* })
876876
*
877+
* @param {Object} [options]
878+
* @param {Session} [options.session=null] the [session](https://docs.mongodb.com/manual/reference/server-sessions/) associated with this operation. If not specified, defaults to the [document's associated session](api.html#document_Document-$session).
877879
* @param {function(err,product)} [fn] optional callback
878880
* @return {Promise} Promise
879881
* @api public
@@ -1819,21 +1821,28 @@ Model.translateAliases = function translateAliases(fields) {
18191821
* not execute [document middleware](/docs/middleware.html#types-of-middleware).
18201822
*
18211823
* @param {Object} conditions
1824+
* @param {Object} [options]
1825+
* @param {Session} [options.session=null] the [session](https://docs.mongodb.com/manual/reference/server-sessions/) associated with this operation.
18221826
* @param {Function} [callback]
18231827
* @return {Query}
18241828
* @api public
18251829
*/
18261830

1827-
Model.remove = function remove(conditions, callback) {
1831+
Model.remove = function remove(conditions, options, callback) {
18281832
_checkContext(this, 'remove');
18291833

18301834
if (typeof conditions === 'function') {
18311835
callback = conditions;
18321836
conditions = {};
1837+
options = null;
1838+
} else if (typeof options === 'function') {
1839+
callback = options;
1840+
options = null;
18331841
}
18341842

18351843
// get the mongodb collection object
18361844
const mq = new this.Query({}, {}, this, this.collection);
1845+
mq.setOptions(options);
18371846

18381847
callback = this.$handleCallbackError(callback);
18391848

@@ -1908,8 +1917,7 @@ Model.deleteMany = function deleteMany(conditions, options, callback) {
19081917
callback = conditions;
19091918
conditions = {};
19101919
options = null;
1911-
}
1912-
else if (typeof options === 'function') {
1920+
} else if (typeof options === 'function') {
19131921
callback = options;
19141922
options = null;
19151923
}

test/docs/transactions.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe('transactions', function() {
2121
return db.
2222
then(() => {
2323
// Skip if not a repl set
24-
if (db.client.topology.constructor.name !== 'ReplSet') {
24+
if (db.client.topology.constructor.name !== 'ReplSet' &&
25+
!db.client.topology.s.description.type.includes('ReplicaSet')) {
2526
_skipped = true;
2627
this.skip();
2728

0 commit comments

Comments
 (0)