Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Could not connect to replica set #132

Open
oliveirajota opened this issue Jul 4, 2016 · 2 comments
Open

Could not connect to replica set #132

oliveirajota opened this issue Jul 4, 2016 · 2 comments

Comments

@oliveirajota
Copy link

I've receiving this error when trying to connect to master and replica together.
"Illegal trailing backslash after database name"

let uri = "mongodb://user:pass@host:port/database";
let uriReplica = "mongodb://user:pass@host:port/database";

let connection =  Mongorito.connect(uri, uriReplica);
@vadimdemedes
Copy link
Owner

Could you post exact code (without login & passwords, ofc)?

@oliveirajota
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants