3

I'm using ReplicaSet with Mongo and when i build the connection string i have all servers hosts and ports - comma delimited.

My question is, shall i add the arbiter address there as well or just the masters and secondaries?

Thank you!

8

Connecting to a replica set

Most drivers will show the following behavior, as far as I know

  1. If only a single node is given, the driver will simply connect to this node.
  2. If the replicaSet option is given in the connection string, the driver will start to explore said replica set to identify all non-hidden members, regardless of the number of nodes given in the connection string.
  3. The same behavior is triggered when multiple nodes are given in the connection string. Since this is a bit more driver dependent than the above (for example, you can give multiple mongos as well), I personally would not rely too much on it.

Should I include an arbiter in the connection string?

The reason why you should always give at least two members of a replica set in a connection string is that this enables the driver to connect to a replica set, even when one node is down. This can be any node (except a hidden one, I suppose, but I have never tried that), since each node is fully aware of the replica set.

In a three node replica set with two data bearing members, it does not make much sense to include the arbiter into the connection string. If you give the two data bearing nodes, and both are unreachable, your replica set is not reachable any more.

In a five node replica set, however, you may include an arbiter in the connection string, since you may want to add 3 nodes altogether to make sure that either you can connect to one of them or can safely assume that the replica set is unavailable.

TL:DR

It does not hurt to include an arbiter in the connection string, though it makes a bit less sense in a minimal replica set consisting of two data bearing nodes and an arbiter.

To be on the safe side, you will almost always include the majority of voting members in your connection string. Which type of member the individual member is does not play a significant role for the purpose of replica set discovery.

I would suggest to always add the replicaSet option to the connection string, and be it just for being clear on the intended purpose.

1

The valid and live members from replica set will automatically detect the arbiter which is in your replica set but not specified in connection.

The driver will redirect the request to only Primary and secondaries knowing that arbiter will not serve any requests. It helps in voting in case of failover.

However, its always good idea to add all members in connection.

  • The arbiter never serve requests. But as for health checks and potentially elections, it will always and constantly respond to requests concerning this. – Markus W Mahlberg Apr 10 '16 at 10:37
  • 1
    Furthermore, it is not the members which do the discovery on connection: it is the driver. Each member of a replica set at all times is aware (from its point of view) wether each other member is up and running . – Markus W Mahlberg Apr 10 '16 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.