Mongoose and multiple database error handling
You may be looking for something like the following:
var localConnectStr = 'mongodb://localhost/test'var mlabConnectStr = 'mongodb://<dbuser>:<dbpassword>@ds123456.mlab.com:25716/<dbname>'var db = mongoose.createConnection(localConnectStr, { useMongoClient: true });var mlabdb = mongoose.createConnection(mlabConnectStr, { useMongoClient: true });
You'll of course want to use your actual mlab uri and database user/pass. But this is how you would handle multiple connections. See createConnection here.
You could use the code you have, checking your local connection, to check mlab.
mlabdb.on('error', console.error);mlabdb.once('open', () => { console.log(rangi.green('Connected To Mlab MongoDB'));});