Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set merges deeply nested objects #14870

Merged
merged 1 commit into from
Sep 9, 2024
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 @@
await person.save();
});

it('set() merge option with double nested', async function () {

Check failure on line 8180 in test/document.test.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses
const PersonSchema = new Schema({
info: {
address: {
city: String,
country: { type: String, default: "UK" },

Check failure on line 8185 in test/document.test.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Strings must use singlequote
postcode: String
},

Check failure on line 8187 in test/document.test.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected trailing comma
}
});

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


const person = new Person({
info: {
address: {
country: "United States",

Check failure on line 8197 in test/document.test.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Strings must use singlequote
city: "New York"

Check failure on line 8198 in test/document.test.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Strings must use singlequote
},

Check failure on line 8199 in test/document.test.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected trailing comma
}
});

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

Check failure on line 8203 in test/document.test.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Strings must use singlequote

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

Check failure on line 8206 in test/document.test.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Trailing spaces not allowed
assert.equal(person.info.address.city, "New York");

Check failure on line 8207 in test/document.test.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Strings must use singlequote
assert.equal(person.info.address.postcode, "12H");

Check failure on line 8208 in test/document.test.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Strings must use singlequote
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