Skip to content

Commit

Permalink
fix(model): support passing options to Model.remove()
Browse files Browse the repository at this point in the history
Fix #8211
  • Loading branch information
vkarpov15 committed Oct 9, 2019
1 parent 7a20276 commit 402db1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions lib/model.js
Expand Up @@ -874,6 +874,8 @@ Model.prototype.$__where = function _where(where) {
* assert.ok(err)
* })
*
* @param {Object} [options]
* @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).
* @param {function(err,product)} [fn] optional callback
* @return {Promise} Promise
* @api public
Expand Down Expand Up @@ -1819,21 +1821,28 @@ Model.translateAliases = function translateAliases(fields) {
* not execute [document middleware](/docs/middleware.html#types-of-middleware).
*
* @param {Object} conditions
* @param {Object} [options]
* @param {Session} [options.session=null] the [session](https://docs.mongodb.com/manual/reference/server-sessions/) associated with this operation.
* @param {Function} [callback]
* @return {Query}
* @api public
*/

Model.remove = function remove(conditions, callback) {
Model.remove = function remove(conditions, options, callback) {
_checkContext(this, 'remove');

if (typeof conditions === 'function') {
callback = conditions;
conditions = {};
options = null;
} else if (typeof options === 'function') {
callback = options;
options = null;
}

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

callback = this.$handleCallbackError(callback);

Expand Down Expand Up @@ -1908,8 +1917,7 @@ Model.deleteMany = function deleteMany(conditions, options, callback) {
callback = conditions;
conditions = {};
options = null;
}
else if (typeof options === 'function') {
} else if (typeof options === 'function') {
callback = options;
options = null;
}
Expand Down
3 changes: 2 additions & 1 deletion test/docs/transactions.test.js
Expand Up @@ -21,7 +21,8 @@ describe('transactions', function() {
return db.
then(() => {
// Skip if not a repl set
if (db.client.topology.constructor.name !== 'ReplSet') {
if (db.client.topology.constructor.name !== 'ReplSet' &&
!db.client.topology.s.description.type.includes('ReplicaSet')) {
_skipped = true;
this.skip();

Expand Down

0 comments on commit 402db1a

Please sign in to comment.