I've got a replica set holding two different databases: db1 and db2. With node-mongodb-native, how do I access these two databases?
I'm trying to do something like this right now:
var mongo = require('mongodb');
var repSet = new mongo.ReplSet( ... );
var conn1 = new mongo.Db('db1', repSet);
var conn2 = new mongo.Db('db2', repSet);
But when executing that last line, I get:
Failed to open database 'ads'! (Error: in process of connection)
Am I doing something wrong?
Turns out I was calling conn1.open() and then conn2.open(), and the error was getting thrown on that second, conn2.open() call. Apparently when re-using a replica set, the connection will already be open. Checking for conn2.state === 'connected' did the trick.