How to configure router to read from nearest Config server?

Hi,

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

systemLog:
   destination: file
   path: /opt/logs/mongodb/router.log
   logAppend: true
net:
   port: 27017
   bindIp: localhost,x.x.x.91,127.0.0.1
sharding:
   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
security:
  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

Hi,

Any pointers on this topic would be appreciated.

Thanks

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
Kevin

1 Like