Skip to content

Commit abedf3c

Browse files
authored
Merge pull request Automattic#14878 from Automattic/vkarpov15/Automatticgh-14861
fix: backport Automattic#14870 to 6.x
2 parents fe17056 + 3910527 commit abedf3c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/document.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
12241224
this.$__setValue(path, null);
12251225
cleanModifiedSubpaths(this, path);
12261226
} else {
1227-
return this.$set(val, path, constructing);
1227+
return this.$set(val, path, constructing, options);
12281228
}
12291229

12301230
const keys = getKeysInSchemaOrder(this.$__schema, val, path);

test/document.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8078,6 +8078,38 @@ describe('document', function() {
80788078
await person.save();
80798079
});
80808080

8081+
it('set() merge option with double nested', async function() {
8082+
const PersonSchema = new Schema({
8083+
info: {
8084+
address: {
8085+
city: String,
8086+
country: { type: String, default: 'UK' },
8087+
postcode: String
8088+
}
8089+
}
8090+
});
8091+
8092+
const Person = db.model('Person', PersonSchema);
8093+
8094+
8095+
const person = new Person({
8096+
info: {
8097+
address: {
8098+
country: 'United States',
8099+
city: 'New York'
8100+
}
8101+
}
8102+
});
8103+
8104+
const update = { info: { address: { postcode: '12H' } } };
8105+
8106+
person.set(update, undefined, { merge: true });
8107+
8108+
assert.equal(person.info.address.city, 'New York');
8109+
assert.equal(person.info.address.postcode, '12H');
8110+
assert.equal(person.info.address.country, 'United States');
8111+
});
8112+
80818113
it('setting single nested subdoc with timestamps (gh-8251)', async function() {
80828114
const ActivitySchema = Schema({ description: String }, { timestamps: true });
80838115
const RequestSchema = Schema({ activity: ActivitySchema });

0 commit comments

Comments
 (0)