-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Do you want to request a feature or report a bug?
feature
What is the current behavior?
When initialising more than one connection (different hosts / servers) its impossible to separate models from the initial app. I have tried to implement useDb(), but this seems to be for the same connection with different DB's hosted on this.
I have also tried to implement mongoose.connections[index].model('ModelName', Schema), this doesn't work if the connection hasn't been run yet (Please note: I'm using mongoose.createConnection()). Using TypeScript imports need to be the first thing in the file and therefore there's no way to create these connections prior to loading the models.
There really needs to be a better way to separate models from connections. Is there nothing that can be done to use a connection such as a useConnection function? The current implementation is unreliable and it's hard to work with.
Has anyone else managed to solve this issue?
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
MongoDB: 4.0.3
Node: v11.12.0
Mongoose: 5.7.5