Skip to content

Commit

Permalink
fix(document): handle a couple edge cases with atomics that happen wh…
Browse files Browse the repository at this point in the history
…en schema defines an array property named 'undefined'

Fix #7756
  • Loading branch information
vkarpov15 committed May 9, 2019
1 parent b9837f0 commit 438d125
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2465,19 +2465,20 @@ Document.prototype.$__dirty = function() {
if (!item) {
return;
}
if (item.path.indexOf(lastPath) !== 0) {
if (lastPath == null || item.path.indexOf(lastPath) !== 0) {
lastPath = item.path + '.';
minimal.push(item);
top = item;
} else {
} else if (top != null &&
top.value != null &&
top.value[arrayAtomicsSymbol] != null &&
top.value.hasAtomics()) {
// special case for top level MongooseArrays
if (top.value && top.value[arrayAtomicsSymbol] && top.value.hasAtomics()) {
// the `top` array itself and a sub path of `top` are being modified.
// the only way to honor all of both modifications is through a $set
// of entire array.
top.value[arrayAtomicsSymbol] = {};
top.value[arrayAtomicsSymbol].$set = top.value;
}
// the `top` array itself and a sub path of `top` are being modified.
// the only way to honor all of both modifications is through a $set
// of entire array.
top.value[arrayAtomicsSymbol] = {};
top.value[arrayAtomicsSymbol].$set = top.value;
}
});

Expand Down
2 changes: 1 addition & 1 deletion lib/types/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ MongooseArray.mixin = {
val = this.toObject.call(val, opts);
} else if (val != null && Array.isArray(val.$each)) {
val.$each = this.toObject.call(val.$each, opts);
} else if (val.valueOf) {
} else if (val != null && typeof val.valueOf === 'function') {
val = val.valueOf();
}

Expand Down

0 comments on commit 438d125

Please sign in to comment.