在等待匹配服务器的30000毫秒后超时 ReadPreferenceServerSelector {readPreference = nearest}。客户观点 群集状态为{type = UNKNOWN,服务器= [{address =:27017, 类型=未知,状态=正在连接, exception = {com.mongodb.MongoSocketReadException:已过早到达 流的结尾}},{地址=:27017,类型=未知, 状态=正在连接,异常= {com.mongodb.MongoSocketReadException: 过早到达流的末尾}}
尝试将MongoDB地图集与Java MongoClient连接时出现此错误
ServerAddress primaryServer = new ServerAddress(<primary_host>,
Integer.parseInt(27017));
ServerAddress secondaryServer = new ServerAddress(<secondary_host>,
Integer.parseInt(27017));
MongoCredential mongoCred = MongoCredential.createScramSha1Credential(<user_name>, <db_name>, <password>.toCharArray());
MongoClientOptions.Builder mongoConf = new MongoClientOptions.Builder();
mongoConf.readPreference(ReadPreference.nearest());
MongoClient mongoClient = new MongoClient(Arrays.asList(primaryServer, secondaryServer), Arrays.asList(mongoCred, mongoCred), mongoConf.build());