Skip to content

Commit 1be4d87

Browse files
committedDec 10, 2020
fix(model): set isNew to false for documents that were successfully inserted by insertMany with ordered = false when an error occurred
Fix #9677
1 parent b2da840 commit 1be4d87

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed
 

‎lib/model.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -3332,9 +3332,13 @@ Model.$__insertMany = function(arr, options, callback) {
33323332

33333333
// `insertedDocs` is a Mongoose-specific property
33343334
const erroredIndexes = new Set(get(error, 'writeErrors', []).map(err => err.index));
3335-
error.insertedDocs = docAttributes.filter((doc, i) => {
3336-
return !erroredIndexes.has(i);
3337-
});
3335+
error.insertedDocs = docAttributes.
3336+
filter((doc, i) => !erroredIndexes.has(i)).
3337+
map(function setIsNewForInsertedDoc(doc) {
3338+
doc.$__reset();
3339+
_setIsNew(doc, false);
3340+
return doc;
3341+
});
33383342

33393343
callback(error, null);
33403344
return;

0 commit comments

Comments
 (0)
Please sign in to comment.