Mongos selection

Hey there,
I couldn’t find information in the documentation on what happens if I specify multiple mongos instances within the connection string, e.G.:

mongodb://mongos0.example.com:27017,mongos1.example.com:27017,mongos2.example.com:27017

Will all instances of my application connect to the mongos0.example.com instance, or will they randomly pick one, or how is the actual mongos instance being selected?

I am using mongoose which uses the latest mongo@3.6.0 node driver.

Hi @Jascha_Brinkmann,

If there is more than one mongos instance in the connection seed list, the driver determines which mongos is the “closest” (i.e. the member with the lowest average network round-trip-time) and calculates the latency window by adding the average round-trip-time of this “closest” mongos instance and the localThresholdMS . The driver will load balance randomly across the mongos instances that fall within the latency window.

See more details here:
https://docs.mongodb.com/manual/core/read-preference-mechanics/#load-balancing

Best
Pavel

2 Likes