Skip to content

Commit 9725d93

Browse files
committed
fix(document): avoid flattening dotted paths in mixed path underneath nested path
Fix #14178
1 parent 44f391b commit 9725d93

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/document.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,6 @@ function $applyDefaultsToNested(val, path, doc) {
472472
return;
473473
}
474474

475-
flattenObjectWithDottedPaths(val);
476-
477475
const paths = Object.keys(doc.$__schema.paths);
478476
const plen = paths.length;
479477

test/document.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12414,6 +12414,29 @@ describe('document', function() {
1241412414
await doc.save();
1241512415
assert.ok(doc);
1241612416
});
12417+
12418+
it('avoids overwriting dotted paths in mixed path underneath nested path (gh-14178)', async function() {
12419+
const testSchema = new Schema({
12420+
__stateBeforeSuspension: {
12421+
field1: String,
12422+
field3: { type: Schema.Types.Mixed },
12423+
}
12424+
});
12425+
const Test = db.model('Test', testSchema);
12426+
let eventObj = new Test({
12427+
__stateBeforeSuspension: { field1: 'test' }
12428+
})
12429+
await eventObj.save();
12430+
const newO = eventObj.toObject();
12431+
newO.__stateBeforeSuspension.field3 = {'.ippo': 5};
12432+
eventObj.set(newO);
12433+
await eventObj.save();
12434+
12435+
assert.strictEqual(eventObj.__stateBeforeSuspension.field3['.ippo'], 5);
12436+
12437+
const fromDb = await Test.findById(eventObj._id).lean().orFail();
12438+
assert.strictEqual(fromDb.__stateBeforeSuspension.field3['.ippo'], 5);
12439+
});
1241712440
});
1241812441

1241912442
describe('Check if instance function that is supplied in schema option is availabe', function() {

0 commit comments

Comments
 (0)