Skip to content

Commit b9d8abd

Browse files
authored
Adapt to changed mongoose behaviour (#73)
fix: updateOne hangs if nothing was found
1 parent 3468f93 commit b9d8abd

File tree

4 files changed

+116
-31
lines changed

4 files changed

+116
-31
lines changed

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ exports.default = function (schema, opts) {
210210
function postUpdateOne(result, next) {
211211
var _this3 = this;
212212

213-
if (result.nModified === 0) return;
213+
if (result.nModified === 0 && !result.upserted) return next();
214214

215215
var conditions = void 0;
216216
if (this._originalId) conditions = { _id: { $eq: this._originalId } };else conditions = mergeQueryConditionsWithUpdate(this._conditions, this._update);
@@ -269,7 +269,7 @@ exports.default = function (schema, opts) {
269269
function postUpdateMany(result, next) {
270270
var _this5 = this;
271271

272-
if (result.nModified === 0) return;
272+
if (result.nModified === 0 && !result.upserted) return next();
273273

274274
var conditions = void 0;
275275
if (this._originalIds.length === 0) conditions = mergeQueryConditionsWithUpdate(this._conditions, this._update);else conditions = { _id: { $in: this._originalIds } };

package-lock.json

Lines changed: 111 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"fast-json-patch": "^2.2.1",
1515
"humps": "^2.0.1",
1616
"lodash": "^4.17.20",
17-
"mongoose": "^5.6.2"
17+
"mongoose": "^5.10.7"
1818
},
1919
"devDependencies": {
2020
"babel-cli": "^6.26.0",

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export default function (schema, opts) {
346346
})
347347

348348
function postUpdateOne(result, next) {
349-
if (result.nModified === 0) return
349+
if (result.nModified === 0 && !result.upserted) return next()
350350

351351
let conditions
352352
if (this._originalId) conditions = { _id: { $eq: this._originalId } }
@@ -388,7 +388,7 @@ export default function (schema, opts) {
388388
}
389389

390390
function postUpdateMany(result, next) {
391-
if (result.nModified === 0) return
391+
if (result.nModified === 0 && !result.upserted) return next()
392392

393393
let conditions
394394
if (this._originalIds.length === 0)

0 commit comments

Comments
 (0)