Skip to content

Commit

Permalink
fix(query): make findOneAndReplace() work with orFail()
Browse files Browse the repository at this point in the history
Fix #8030
  • Loading branch information
vkarpov15 committed Jul 30, 2019
1 parent f10f621 commit 9db4857
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -3286,15 +3286,15 @@ Query.prototype._findOneAndReplace = wrapThunk(function(callback) {
castedDoc = castedDoc.toBSON();
}

this._collection.collection.findOneAndReplace(filter, castedDoc, options, (err, res) => {
this._collection.collection.findOneAndReplace(filter, castedDoc, options, _wrapThunkCallback(this, (err, res) => {
if (err) {
return callback(err);
}

const doc = res.value;

return this._completeOne(doc, res, callback);
});
}));
});
});

Expand Down Expand Up @@ -4199,6 +4199,7 @@ Query.prototype.orFail = function(err) {
}
break;
case 'findOneAndUpdate':
case 'findOneAndReplace':
if (get(res, 'lastErrorObject.updatedExisting') === false) {
throw _orFailError(err, this);
}
Expand Down

0 comments on commit 9db4857

Please sign in to comment.