New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discriminated methods being ignored, base methods called after app restart #14522
Comments
I've even tried getting a raw object and then re-hydrating the document. Even thought the
|
I've figured it out. When the app is restarted, the discriminated models are no longer "registered". They would only be registered with Mongoose when they are first accessed. To fix this, I have created a method that initialises all the discriminators on dbConnect() just by referencing each model. Maybe there's a more generic version or different way I should structure my code? |
So the issue is that your discriminators are defined in a file that you don't The |
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days |
This issue was closed because it has been inactive for 19 days and has been marked as stale. |
Prerequisites
Mongoose version
8.3.0
Node.js version
20.12.2
MongoDB server version
Cloud Atlas
Typescript version (if applicable)
5.4.3
Description
Methods that have been "overloaded" or replaced by discriminated child models are ignored after the app is restarted.
With a base model and discriminated model, the discriminated one can be inserted into Mongo, then retrieved, then the discriminated methods can be triggered. However, if the app is closed and started again, any existing documents in the database are then retrieved as the base model instead of the discriminated model so the base methods are called instead.
Steps to Reproduce
Base documene
Discriminated documents
Usage
Expected Behavior
The discriminated methods should be called even if the document wasn't created in this session.
The text was updated successfully, but these errors were encountered: