Getters are not executed automatically with Express' res.json() #13049
Labels
docs
This issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone
Prerequisites
Mongoose version
6.9.0
Node.js version
18.13.0
MongoDB server version
5.0.14
Typescript version (if applicable)
No response
Description
The documentation mentions:
However, it doesn't seem to be the case with
find()
(not sure about other methods).Steps to Reproduce
I have some numeric keys in my schema, e.g.:
and my controller function:
On the front-end, a nested object is received:
Expected Behavior
One would expect the getter is executed at the time of conversion to JSON but for some reason it's not, unless the
toJSON.getters
option is explicitly set totrue
:So it's one of the three:
The text was updated successfully, but these errors were encountered: