Skip to content

Commit

Permalink
fix(document): if setting unselected nested path, don't overwrite nes…
Browse files Browse the repository at this point in the history
…ted path

Fix #5800
  • Loading branch information
vkarpov15 committed Nov 20, 2017
1 parent 93ea193 commit 82c615c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,14 @@ Document.prototype.$set = function(path, val, type, options) {
curPath += (curPath.length > 0 ? '.' : '') + parts[i];
if (!cur) {
this.$set(curPath, {});
// Hack re: gh-5800. If nested field is not selected, it probably exists
// so `MongoError: cannot use the part (nested of nested.num) to
// traverse the element ({nested: null})` is not likely. If user gets
// that error, its their fault for now. We should reconsider disallowing
// modifying not selected paths for v5.
if (!this.isSelected(curPath)) {
this.unmarkModified(curPath);
}
cur = this.getValue(curPath);
}
}
Expand Down

0 comments on commit 82c615c

Please sign in to comment.