toJSON options gets passed to implicitly created schemas, including transform #13599
Closed
2 tasks done
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
7.2.0+
Node.js version
20.x
MongoDB server version
6.x
Typescript version (if applicable)
No response
Description
A new feature was added (#13325) where
toJSON
andtoObject
options get passed to implicitly created schemas in a schema. I believe this was so that if you setvirtuals: true
andgetters: true
that those options would get passed. Another option gets passed that gives us unexpected results:transform
. We use thistransform()
function to modify the document before it goes out. Before it was only being run for the top level schema, but now it gets run for every sub document.Steps to Reproduce
This will produce logs that look something like this:
Expected Behavior
Expected behavior is that the defined transform function would only apply to the schema on which it is defined.
The workaround is to wrap all of the implicit schemas with
new mongoose.Schema()
.The text was updated successfully, but these errors were encountered: