Reputation: 12230
I read that in a nodejs
application, if we use a mongoose
object using
var obj = require('mongoose')
;
then, wherever we create a new mongoose
object (say, in another file), then the same cached copy is used throughout. In that case, how can we connect to multiple database instances of mongoDB
in the same nodejs
app ?
Upvotes: 0
Views: 1321
Reputation: 145994
You can use mongoose.createConnection to connect to a separate database, and then using the connection
object that generates, you can define models from that database using connection.model
.
Upvotes: 1