-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Is it possible to remove default empty connection from mongoose.connections
?
#8302
Comments
It should be safe, but the better question is, why do you need to do this? If you want to use |
@vkarpov15 well, i am using nestjs framework, which got its own module to connect to db, where I only provide params for connection This is the main reason why I asked this question Other reason was that, if I instance model differently from suggested way by framework, and I do nestjs/mongoose#109 |
So then why not use |
Doing so does not work because the first connection is an empty connection. The following error is thrown:
It might be the case where the schema is not present(let's say, something dynamic where that schema could be anything). I'm building a plugin where that's the case. |
@syned13 I don't understand the issue. What do you mean by "the first connection is an empty connection"? |
Should be possible now with |
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. |
… false after Mongoose instance created re: #8302
…deleting initial connection Re: #8302
Remove default connection if setting createInitialConnection to false after Mongoose instance created
With #14679, |
Do you want to request a feature or report a bug?
feature
What is the current behavior?
When mongoose is imported in some file, it will automatically call constructor of mongoose, where we have call of
createConnection()
method, without any uri.That means that
mongoose.connections[0]
is a bit useless. So, when I use.createConnection(someUri, options)
to have real connection to db and my connection will be on 2nd place in an array of connections. Problem here is thatmongoose.model()
won't be able to properly instance model, because it will watch default connection, which is equal tomongoose.connections[0]
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
Expecting that this default connection disappear from list of connections when real connection is provided and to override
mongoose.connection
with first connection from listWhat are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node 12.13.0
mongoose 5.7.7
mongoDB 3.6.2
The text was updated successfully, but these errors were encountered: