-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Discriminator Method Modifies Schema Argument in Mongoose #14821
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
"Facing the same issue. The schema variable I pass to the discriminator method is being modified. While we can work around it by creating the discriminator like this:
the question remains: is it valid for the discriminator method to modify the argument, especially when it's a variable we're using?" |
facing the same issue |
This was referenced Sep 19, 2024
This was referenced Sep 19, 2024
This was referenced Sep 25, 2024
This was referenced Sep 25, 2024
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Prerequisites
Mongoose version
7.2.2
Node.js version
20.12.2
MongoDB server version
7.0
Typescript version (if applicable)
No response
Description
When using Mongoose's discriminator method to create a new discriminator from a parent model, the method modifies the schema object passed as an argument. Specifically, it adds fields from the parent model's schema into the discriminator's schema, which is an unexpected and potentially invalid behavior.
Steps to Reproduce
Expected Behavior
Should the adminSchema remain unmodified after being passed to the discriminator method? We expect the fields from the userSchema to be combined with the adminSchema internally by Mongoose, without affecting the original schema object passed as an argument.
The text was updated successfully, but these errors were encountered: