Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
this.$__setValue(path, null);
cleanModifiedSubpaths(this, path);
} else {
return this.$set(val, path, constructing);
return this.$set(val, path, constructing, options);
}

const keys = getKeysInSchemaOrder(this.$__schema, val, path);
Expand Down
32 changes: 32 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8177,6 +8177,38 @@ describe('document', function() {
await person.save();
});

it('set() merge option with double nested', async function () {
const PersonSchema = new Schema({
info: {
address: {
city: String,
country: { type: String, default: "UK" },
postcode: String
},
}
});

const Person = db.model('Person', PersonSchema);


const person = new Person({
info: {
address: {
country: "United States",
city: "New York"
},
}
});

const update = { info: { address: { postcode: "12H" } } };

person.set(update, undefined, { merge: true });

assert.equal(person.info.address.city, "New York");
assert.equal(person.info.address.postcode, "12H");
assert.equal(person.info.address.country, "United States");
});

it('setting single nested subdoc with timestamps (gh-8251)', async function() {
const ActivitySchema = Schema({ description: String }, { timestamps: true });
const RequestSchema = Schema({ activity: ActivitySchema });
Expand Down