De beste manier is om tags te gebruiken zoals vermeld in de Mongodb-handleiding.
https://docs.mongodb.com/manual/ tutorial/configure-replica-set-tag-sets/
conf = rs.conf()
conf.members[0].tags = { "offline": "false"}
conf.members[1].tags = { "offline": "false"}
conf.members[2].tags = { "offline": "true"}
rs.reconfig(conf)
In de client stel je gewoon de leesvoorkeur in op die tag
MongoClientOptions options = MongoClientOptions
.builder()
.connectionsPerHost(config.connectionLimit)
.readPreference(TaggableReadPreference.secondaryPreferred(new TagSet(new Tag("offline", "true"))))
.socketTimeout(config.socketTimeout)
.connectTimeout(config.connectionTimeout)
.build();
mongo = new MongoClient(NewsDAOConfig.parseAddresses(config.mongoAddress), options);