Skip to content

Commit

Permalink
fix(document): handle validating deeply nested subdocuments underneat…
Browse files Browse the repository at this point in the history
…h nested paths with required: false

Fix #12021
  • Loading branch information
vkarpov15 committed Jul 5, 2022
1 parent 320fcad commit 04966eb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/document.js
Expand Up @@ -1409,7 +1409,11 @@ Document.prototype.$set = function $set(path, val, type, options) {
// later in `$__set()` because we don't take `_doc` when we iterate through
// a single nested doc. That's to make sure we get the correct context.
// Otherwise we would double-call the setter, see gh-7196.
val = schema.applySetters(val, this, false, priorVal, options);
if (options != null && options.overwriteImmutable) {
val = schema.applySetters(val, this, false, priorVal, { overwriteImmutable: true });
} else {
val = schema.applySetters(val, this, false, priorVal);
}
}

if (Array.isArray(val) &&
Expand Down
2 changes: 1 addition & 1 deletion test/document.test.js
Expand Up @@ -11522,7 +11522,7 @@ describe('document', function() {
{
nested: {
type: SubSubSchema,
required: false
required: false // <-- important
}
},
{ _id: false }
Expand Down

0 comments on commit 04966eb

Please sign in to comment.