'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
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 and I am using spring-data-mongodbþspr. 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
Solution 1:[1]
The mongos is caching the CSRS(Config Server as Replica Set ) data, so in most of the cases reading from nearest is not so important since the metadata will be in mongos memory. When you set readPreference: nearest from your app driver it affects how you read from the data members ( the driver mantain a list with nearest replicaSet members so he knows where to route the queries).
From the mongo shell client you can set the default read preference as follow:
db.getMongo().setReadPref('nearest')
Also you can set read preference per individual query , example:
db.collection.find({ }).readPref("nearest")
But you cannot set readPreference explicitely for mongos
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
