I currently have this code for my mongoose.js connection:
var mongoose = require('mongoose'); var uriUtil = require('mongodb-uri'); var mongodbUri = 'mongodb://localhost/db_name'; var mongooseUri = uriUtil.formatMongoose(mongodbUri); mongoose.connect(mongooseUri); module.exports = mongoose;
A file that requires a connection, test.js :
var mongoose = require('../model/mongoose'); var schema = mongoose.Schema({...});
How to update mongoose.js to use multiple connections with mongoose.createConnection (...) function?
I start with changes for only one connection when I make such changes:
var mongoose = require('mongoose'); mongoose.createConnection('mongodb://localhost/db_name'); mongoose.open('localhost'); module.exports = mongoose;
I get "undefined is not a function". If I use this code:
var mongoose = require('mongoose'); db = mongoose.createConnection('mongodb://localhost/db_name'); db.open('localhost'); module.exports = mongoose;
I get "Error: attempt to open a closed connection"
Any tips?
Pumych
source share