Skip to content

Commit b5b21fb

Browse files
committed
fix(model): catch error when insertMany fails to cast document
Fixes #8363
1 parent c6f3dd2 commit b5b21fb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/model.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3206,10 +3206,15 @@ Model.$__insertMany = function(arr, options, callback) {
32063206

32073207
const toExecute = [];
32083208
const validationErrors = [];
3209+
32093210
arr.forEach(function(doc) {
32103211
toExecute.push(function(callback) {
32113212
if (!(doc instanceof _this)) {
3212-
doc = new _this(doc);
3213+
try {
3214+
doc = new _this(doc);
3215+
} catch (err) {
3216+
return callback(err);
3217+
}
32133218
}
32143219
if (options.session != null) {
32153220
doc.$session(options.session);

0 commit comments

Comments
 (0)