Question

Suppose I have a replica set with one primary P and three secondaries S1, S2, and S3. Suppose an application creates a Mongo clent with this constructor. The seeds list is {P, S1, S2}. Note the list does not contain S3.

Suppose the application uses secondPreferred and both S1 and S2 are down. Will the queries go to P or S3 ?

The javadoc says It will find all members (the master will be used by default), and I guess the queries will go to S3. Is it correct ?

Was it helpful?

Solution

The seed list is exactly that, the driver will query that list to understand the map of the replica set. This means it can actually use members NOT on that list, i.e. it can use S3.

When the driver has to detect a change in the replica set, either by failover or by starting up it will query one of the members of the seed list for basically a rs.status() and it will store the result in itself for a time that the driver deems worthy to refresh it, or something happens that forces the driver to refresh it (i.e. failover).

So the answer is yes, it will go for S3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top