Skip to content

Commit 936ddfb

Browse files
committed
fix(update): handle subdocument pre('validate') errors in update validation
Fix #7187
1 parent 98b3b09 commit 936ddfb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/document.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1932,9 +1932,11 @@ Document.prototype.validate = function(options, callback) {
19321932
options = null;
19331933
}
19341934

1935-
return utils.promiseOrCallback(callback, cb => this.$__validate(options, function(error) {
1936-
cb(error);
1937-
}), this.constructor.events);
1935+
return utils.promiseOrCallback(callback, cb => {
1936+
this.$__validate(options, function(error) {
1937+
cb(error);
1938+
});
1939+
}, this.constructor.events);
19381940
};
19391941

19401942
/*!

lib/helpers/updateValidators.js

+3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ module.exports = function(query, schema, castedDoc, options, callback) {
136136
_err.path = updates[i] + '.' + key;
137137
validationErrors.push(_err);
138138
}
139+
} else {
140+
err.path = updates[i];
141+
validationErrors.push(err);
139142
}
140143
}
141144
callback(null);

0 commit comments

Comments
 (0)