Den bedste måde er at bruge tags som angivet i mongodb manual.
https://docs.mongodb.com/manual/ tutorial/configure-repica-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)
I klienten indstiller du bare læsepræferencen til det 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);