Mongo connect to a replication set command line option

image
In the manual, it says you can connect to a replication set with command options like this. My question is do you have to list all the members after the forward-slash? If not, what’s the difference between listing one or two or any number of members? Does it always direct you to the primary node? If so what’s the point of listing any member?

Thank you.

Imagine a 5 node replica set and your connection string was this:
replSet/host1,host2

In the event that host1 and host2 go down, you will not be able to connect to your replica set.

So, in order to guarantee that your client can connect to the replica set, supply all 5 nodes for better discoverability.

1 Like

Thank you. I have a follow up question. Suppose I have 5 nodes from host1 to host 5. Host 3 is the primary node and it’s not down.

When I connect to the replica set with replSet/host1, host2, it will direct me to host3, the primary node, right?

That’s right. That’s the default behaviour.

Hi @Ziwen_Song_32480,

If in case you are also interested in knowing about the connection string format used in MongoDB then please refer this page.

Let us know if you have any other questions :slight_smile:

~ Shubham