Skip to content

Commit 16b6a37

Browse files
committed
fix(model): avoid throwing error when bulkSave() called on a document with no changes
Fix #10437
1 parent c1ce3c9 commit 16b6a37

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/model.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3729,18 +3729,21 @@ Model.buildBulkWriteOperations = function buildBulkWriteOperations(documents, op
37293729
}
37303730

37313731
const delta = document.$__delta();
3732-
const where = document.$__where(delta[0]);
3733-
const changes = delta[1];
3734-
3735-
_applyCustomWhere(document, where);
3736-
3737-
document.$__version(where, delta);
37383732

37393733
if (document.isNew) {
3734+
// new document
37403735
accumulator.push({
37413736
insertOne: { document }
37423737
});
3743-
} else if (!utils.isEmptyObject(changes)) {
3738+
} else if (delta != null && !utils.isEmptyObject(delta[0])) {
3739+
// document with changes
3740+
const where = document.$__where(delta[0]);
3741+
const changes = delta[1];
3742+
3743+
_applyCustomWhere(document, where);
3744+
3745+
document.$__version(where, delta);
3746+
37443747
accumulator.push({
37453748
updateOne: {
37463749
filter: where,

0 commit comments

Comments
 (0)