-
Notifications
You must be signed in to change notification settings - Fork 116
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
Can't instance a model from mongoose after update from v4 to v6 #109
Comments
Could you please provide a minimal repository which reproduces your issue? :) |
https://github.com/NenadJovicic/test-nest-project |
@kamilmysliwiec did you have time to look into this? |
still no update on this? @kamilmysliwiec |
@NenadJovicic for now i doing something like this
|
@igorivaniuk thanks for help @kamilmysliwiec tested out also with mongoose 5.0.1, because I used that version with nest v4, and there is a same problem. because default connection for mongoose that is set up does not contain all collections that my db has, only 1 collection, and 2nd connection from list of |
@kamilmysliwiec I found a reason why is this happening, that we have 2 different connections with mongoose, and that 2nd one is only valid one, or connection to my DB. It happened in this commit where you changed from So, is there any way to fix this? To not add that first default connection on import or to return it to |
You can inject the |
const someModel = mongoose.model(EventModel.name, EventSchema); |
If I had to bet, it has to deal with how you import |
I'm submitting a...
Duplicated issue https://github.com/nestjs/nest/issues/2585
but I was not sure where should I actually report this bug, so, I am also opening it here
Current behavior
I was using v4 of nestjs and i was instancing new mongoose model with
After upgrading nest to v6, this is not working anymore. I switched to officially suggested way of using it with
@InjectModel()
, but there is still a case where I have to instance model like this.I want to write a prehook in which I want to do some query on some model.
But when I do it like this, it can't execute a query, and it does not throw an error. But it stops execution of code.
My assumption is that somehow,
mongoose.connection
is not set globally, so, model does not know through which connection to execute query.Expected behavior
Expecting that using
mongoose.model()
still can execute query, or if it is possible somehow to extract connection fromapp.module
Minimal reproduction of the problem with instructions
Some example code, which should be executed, not providing full example, I think it is not necessary.
I can't use this https://docs.nestjs.com/recipes/mongodb, because I don't need this feature in some provider or module, so no option to inject it
What is the motivation / use case for changing the behavior?
Environment
The text was updated successfully, but these errors were encountered: