Do I need to specify all the host for replica Set in Mongoose, Express-session-mongo and mongolian?

StackOverflow https://stackoverflow.com/questions/8364808

I have MongoDB replica Set as:

Host1: 10.10.10.1:27017
Host2: 10.10.10.1:27018
Host3: 10.10.10.2:27017
Host4: 10.10.10.2:27018

When I set the connection (e.g. IN Mongoose), I have to do this:

mongoose.connectSet('mongodb://10.10.10.1:271017/mydb,
mongodb://10.10.10.1:27018/mydb,
mongodb://10.10.10.2:27107/mydb, mognodb://10.10.10.27108/mydb);

can I just do this?

mongoose.connectSet('mongodb://10.10.10.1/mydb, mongodb://10.10.10.2/mydb');

How about express-session-mongo and mongolian? how to set up the connection to replica set?

Why I have to define all the host names? shouldn't the driver know all the primary and secondary and keep the lookup table, instead of manually define it during setting up the connection?

有帮助吗?

解决方案

so the mongodb driver that is used by mongoose will find all members of the replicaset if you have at least one member in the original set. This is due to each member in a replicaset knowing about all the other members. But the more servers you know about the better as it makes it more likely to find a server in case your only passed in server is down.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top