Skip to content

Commit 9178805

Browse files
committedSep 10, 2024·
fix: backport #14870 to 6.x
1 parent fe17056 commit 9178805

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
 

‎lib/document.js

+1-1
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

+32
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)
Please sign in to comment.