How to configure router to read from nearest Config server?


I have configured Config servers as a replica set of 5 members. So, now to interact with the Config servers replica set, I am running 3 routers from three different machines, and the configuration of the routers looks something like below

   destination: file
   path: /opt/logs/mongodb/router.log
   logAppend: true
   port: 27017
   bindIp: localhost,x.x.x.91,
   configDB: cfrs/x.x.x.1:27019,x.x.x.2:27019,x.x.x.3:27019,x.x.x.4:27019,x.x.x.5:27019
  keyFile: /opt/certs/mongodb/keyfile

Now my spring boot application interacts with these routers. Since mongos tracks what data is on which shard by caching the metadata from the config servers, is it possible to configure the mongos to read the metadata about the shards from the nearest Config server?

Also, how to configure the routers to read the data from the nearest shard node i.e. readPreference? Though I am setting the readPreference from Spring boot using MongoDB driver, I am not sure whether this readPreference is applicable when reading data from the Shard replica set or from the Config servers replica set?

Thanks in advance


Any pointers on this topic would be appreciated.


Hi @Allwyn_Jesu

I believe currently mongos are using “nearest” read preference as default, but I don’t believe there is a way to change this setting at this point in time.

The reads will be routed to the shards according to the read preference setup for the query or the connection. The mongos router will just pass it on to the shards (see Read Preference for Sharded Clusters).

Best regards


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.