-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.6.0
Node.js version
18.15.0
MongoDB server version
NA
Typescript version (if applicable)
No response
Description
When using document set with the merge option set to true if there are multiple nested fields the deeply nested fields are ignored
Steps to Reproduce
const { Schema, model } = require('mongoose');
const personSchema = new Schema({
info: {
address: {
city: String,
country: { type: String, default: "UK" },
postcode:String
},
}
});
const personModel = model("collection", personSchema);
const document = new personModel({
info: {
address: { country: "United States", city: "New York" },
}
});
console.log(document);
document.$set({ info: { address: { postcode: "12H" } } }, null, { merge: true });
console.log(document);
Expected Behavior
For this code example I get
{
info: { address: { postcode: '12H', country: 'UK' } },
_id: new ObjectId('66d693ee34802938adef5702')
}
I would expect to get
{
info: { address: { city: 'New York', country: 'United States', postcode: '12H' } },
_id: new ObjectId('66d692b9c9fe017af8ab4f78')
}
Metadata
Metadata
Assignees
Labels
No labels