Document.prototype.toObject() should run all getters on fields in subdocuments when getters option is set to true #14835
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
8.5.4
Node.js version
20.17.0
MongoDB server version
7.0.11
Typescript version (if applicable)
No response
Description
In versions 8.5.0 and prior, a call to Document.prototype.toObject() would run getters defined in schemas for subdocuments of arbitrary depth. In 8.5.1 and subsequent versions, toObject() will not run getters for subdocuments nested more than 1 level deep.
Getters should be run on all subdocument fields.
Steps to Reproduce
The following code will run the getters on field1 and field2 in mongoose versions 8.5.0 and prior, and will not run the getter for field2 in 8.5.1 and subsequent versions:
The above test will succeed on 8.5.0 and previous, and fail on 8.5.1 and subsequent versions.
Expected Behavior
All defined getters should be run for nested subdocuments.
The text was updated successfully, but these errors were encountered: