-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
helpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessaryThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
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.16.2
Node.js version
20.10.0
MongoDB server version
6.0.2
Typescript version (if applicable)
5.8.3
Description
When updating a model schema by adding a new field with a default value, retrieving any record and then executing the getChanges
method returns a MongoDB instruction to update the record with the new field and its default value (a very nice feature!).
However, if I execute the modifiedPaths
or isModified
methods, they return an empty array and false, respectively. Why do these results mismatch?
Reproduction link here.
Steps to Reproduce
- Create a model
- Insert a document
- Add a field with a default value to the schema
- Query the inserted document
- Call the
getChanges
,modifiedPaths
, andisModified
methods
Expected Behavior
My goal is to automatically update a document when new fields are added to the schema. For example, I would like to check for any changes by calling the isModified
method, and if it returns true, execute save
.
Metadata
Metadata
Assignees
Labels
helpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessaryThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary