目前,我的产品具有2个辅助mongo节点和1个主要mongo节点,我想从特定的辅助节点读取数据。请帮助我如何使用java从特定的辅助节点读取数据。
当前代码:::
MongoClientOptions.Builder optionsBuilder = MongoClientOptions.builder();
optionsBuilder.connectTimeout(Integer.parseInt(connectionTimeOut));
optionsBuilder.serverSelectionTimeout(Integer.parseInt(serverSelectionTimeOut));
optionsBuilder.socketTimeout(Integer.parseInt(socketTimeOut));
optionsBuilder.connectionsPerHost(Integer.parseInt(connections));
optionsBuilder.maxConnectionIdleTime(Integer.parseInt(maxConnectionIdleTime));
optionsBuilder.minConnectionsPerHost(Integer.parseInt(minConnectionsPerHost));
optionsBuilder.socketKeepAlive(true);
if(Boolean.valueOf(ValidationProperties.getValue("clm.db.useSecondaryMongoForRead"))) {
logger.info("Read is going for secondary mongoDB");
optionsBuilder.readPreference(ReadPreference.secondaryPreferred());
}