Changing a schema path using schema.path
significantly affects performance
#15253
Closed
2 tasks done
Labels
Milestone
Prerequisites
Mongoose version
8.10.0
Node.js version
v18.19.0
MongoDB server version
8.0.4
Typescript version (if applicable)
No response
Description
When using
schema.path
to add a SingleNested type to a preexisting schema, adds the new SingleNested children to thechildSchemas
schema property, regarding of whether it was already in the array. This affectssave()
operations on large documents, with deeply nested documents.Multiple calls to the
path
method make the issue exponentially worse.We've found that calling
_gatherChildSchemas()
is an effective workaround and fixes the issue.Steps to Reproduce
Expected Behavior
The save operation should not take more than 100ms, which is the case when you only call the
path
function once.The text was updated successfully, but these errors were encountered: