Closed
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
6.12.1
Node.js version
14.18.1
MongoDB server version
4.4
Typescript version (if applicable)
No response
Description
Hi, the following code behaves differently in both versions v5.12.5 and v6.x.x.
Note: modified paths are not returning as expected when we use .set() with nested paths as an object.
var mongoose = require('mongoose')
let Schema = mongoose.Schema
var eventSchema = new Schema({
name: { type: String },
__stateBeforeSuspension: {
field1: { type: String },
field2: { type: String },
jsonField: {
name: { type: String }
}
}
})
var Event = mongoose.model('Event', eventSchema)
async function run() {
await mongoose.connect('mongodb://localhost:27017');
let eventObj = new Event({ name: 'event object', __stateBeforeSuspension: { field1: 'test', jsonField: { name: 'test3' }} })
eventObj.save(function (err, eventObj) {
var newObject = eventObj.toObject()
newObject.__stateBeforeSuspension = { field1: '12', jsonField: { name: 'test4' }}
eventObj.set(newObject)
var modifiedPaths = eventObj.modifiedPaths()
console.log(modifiedPaths)
})
}
run();
Output with v5.12.5 :
[
'__stateBeforeSuspension',
'__stateBeforeSuspension.field1',
'__stateBeforeSuspension.jsonField',
'__stateBeforeSuspension.jsonField.name'
]
Output with v6.12.1 :
[ '__stateBeforeSuspension', '__stateBeforeSuspension.jsonField' ]
The modified paths are returning differently in both versions.
Note: We have raised a different issue similar to .set() one. for more info please refer to #14022
Steps to Reproduce
Added the full-fledged details on how to reproduce the issue in the description with a code snippet.
Expected Behavior
No response