Skip to content

Schema.isModified not always accurate for subschema paths #8223

@quinnlas

Description

@quinnlas

Do you want to request a feature or report a bug?
bug

What is the current behavior?
With a schema like so:

const secondLevelSchema = new Schema({
  id: Number,
  text: String
})

const topLevelSchema = new Schema({
  secondLevel: {
    type: secondLevelSchema
  }
}

If you create a new topLevelItem and set one of the properties of secondLevel but not the other,
for instance:
new TopLevelModel({ secondLevel: { text: 'example' } })

then you will have the following strange behavior for the other property:

topLevelItem.isModified('secondLevel.id') //true
topLevelItem.secondLevel.isModified('id')) //false

What is the expected behavior?
both values should be false, since the id has not been modified

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions