使用Java从特定的辅助节点读取数据

时间:2019-06-18 10:58:41

标签: java mongo-java mongo-java-driver mangodb

目前,我的产品具有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());

            }

0 个答案:

没有答案