Skip to content

Commit

Permalink
fix(query): correctly return full deleteOne(), deleteMany() result
Browse files Browse the repository at this point in the history
Fix #11211
  • Loading branch information
vkarpov15 committed Feb 27, 2022
1 parent dd44992 commit 601650a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
6 changes: 3 additions & 3 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -2980,7 +2980,7 @@ Query.prototype._remove = wrapThunk(function(callback) {

callback = _wrapThunkCallback(this, callback);

return Query.base.remove.call(this, helpers.handleDeleteWriteOpResult(callback));
return Query.base.remove.call(this, callback);
});

/**
Expand Down Expand Up @@ -3066,7 +3066,7 @@ Query.prototype._deleteOne = wrapThunk(function(callback) {

callback = _wrapThunkCallback(this, callback);

return Query.base.deleteOne.call(this, helpers.handleDeleteWriteOpResult(callback));
return Query.base.deleteOne.call(this, callback);
});

/**
Expand Down Expand Up @@ -3152,7 +3152,7 @@ Query.prototype._deleteMany = wrapThunk(function(callback) {

callback = _wrapThunkCallback(this, callback);

return Query.base.deleteMany.call(this, helpers.handleDeleteWriteOpResult(callback));
return Query.base.deleteMany.call(this, callback);

This comment has been minimized.

Copy link
@AbdelrahmanHafez

AbdelrahmanHafez Feb 27, 2022

Collaborator

@vkarpov15
Is this a breaking change?

This comment has been minimized.

Copy link
@vkarpov15

vkarpov15 Mar 2, 2022

Author Collaborator

@AbdelrahmanHafez I would argue not. At worst, it would be a minor release because it adds properties to the result of delete calls rather than removes them. Before this change, deletedCount was the only property that showed up because the new version of the MongoDB driver doesn't have a result property. Now, we get deletedCount and a couple of others, like acknowledged.

This comment has been minimized.

Copy link
@AbdelrahmanHafez

AbdelrahmanHafez Mar 2, 2022

Collaborator

I see. that's fine then.
Thanks for the clarification.

});

/*!
Expand Down
20 changes: 0 additions & 20 deletions lib/queryhelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,23 +308,3 @@ function makeLean(val) {
option.options.lean = val;
};
}

/*!
* Handle the `WriteOpResult` from the server
*/

exports.handleDeleteWriteOpResult = function handleDeleteWriteOpResult(callback) {
return function _handleDeleteWriteOpResult(error, res) {
if (error) {
return callback(error);
}
const mongooseResult = Object.assign({}, res.result);
if ((res && res.result && res.result.n || null) != null) {
mongooseResult.deletedCount = res.result.n;
}
if (res.deletedCount != null) {
mongooseResult.deletedCount = res.deletedCount;
}
return callback(null, mongooseResult);
};
};

0 comments on commit 601650a

Please sign in to comment.