Open oliveirajota opened 8 years ago
Could you post exact code (without login & passwords, ofc)?
The problem was adding the database string on the master url and the "mongodb://" string on the replica set url.
The solution was mount a single url string with all the correct parameters as described on the MongoDB Documentation found here.
Also I've passed the replica set name and slaveOk=true on the options parameters.
This is the working code:
import mongorito from 'mongorito';
import util from 'util';
const uri = util.format(
'mongodb://%s:%s@%s:%s',
'user',
'pass',
'host',
'port'
);
const uriReplica = util.format(
'%s:%s/%s?slaveOk=true&replicaSet=%s',
'host_replica',
'port',
'database',
'replicaName'
);
const url = util.format('%s,%s', uri, uriReplica);
// url = 'mongodb://user:pass@host:port,host_replica:port/database?slaveOk=true&replicaSet=replicaName'
export default mongorito.connect(url);
Mongorito was adding the 'mongodb://' string even if I doesn't pass it on the second url.
I've receiving this error when trying to connect to master and replica together. "Illegal trailing backslash after database name"