Skip to content

Commit

Permalink
fix(model): catch error when insertMany fails to cast document
Browse files Browse the repository at this point in the history
  • Loading branch information
Fonger committed Nov 20, 2019
1 parent c6f3dd2 commit b5b21fb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/model.js
Expand Up @@ -3206,10 +3206,15 @@ Model.$__insertMany = function(arr, options, callback) {

const toExecute = [];
const validationErrors = [];

arr.forEach(function(doc) {
toExecute.push(function(callback) {
if (!(doc instanceof _this)) {
doc = new _this(doc);
try {
doc = new _this(doc);
} catch (err) {
return callback(err);
}
}
if (options.session != null) {
doc.$session(options.session);
Expand Down

0 comments on commit b5b21fb

Please sign in to comment.