Skip to content

Commit 04966eb

Browse files
committed
fix(document): handle validating deeply nested subdocuments underneath nested paths with required: false
Fix #12021
1 parent 320fcad commit 04966eb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/document.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,11 @@ Document.prototype.$set = function $set(path, val, type, options) {
14091409
// later in `$__set()` because we don't take `_doc` when we iterate through
14101410
// a single nested doc. That's to make sure we get the correct context.
14111411
// Otherwise we would double-call the setter, see gh-7196.
1412-
val = schema.applySetters(val, this, false, priorVal, options);
1412+
if (options != null && options.overwriteImmutable) {
1413+
val = schema.applySetters(val, this, false, priorVal, { overwriteImmutable: true });
1414+
} else {
1415+
val = schema.applySetters(val, this, false, priorVal);
1416+
}
14131417
}
14141418

14151419
if (Array.isArray(val) &&

test/document.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11522,7 +11522,7 @@ describe('document', function() {
1152211522
{
1152311523
nested: {
1152411524
type: SubSubSchema,
11525-
required: false
11525+
required: false // <-- important
1152611526
}
1152711527
},
1152811528
{ _id: false }

0 commit comments

Comments
 (0)