Description
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 that mongoose.model()
won't be able to properly instance model, because it will watch default connection, which is equal to mongoose.connections[0]
If the current behavior is a bug, please provide the steps to reproduce.
const mongoose = require('mongoose');
(() => {
console.log('Number of connections is', mongoose.connections.length); // will print that there is one connection
})();
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 list
What 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