java - MongoTimeoutException:没有服务器匹配 - MongoDB Atlas
问题描述
几天来,我无法连接到 Altas 托管的任何 MongoDB 数据库。我总是收到 MongoTimeoutException
Exception in thread "Thread-9" com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@3691e69a. Client view of cluster state is {type=REPLICA_SET, servers=[{address=statify-shard-00-02.st9vh.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: extension (5) should not be presented in certificate_request}}, {address=statify-shard-00-00.st9vh.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: extension (5) should not be presented in certificate_request}}, {address=statify-shard-00-01.st9vh.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: extension (5) should not be presented in certificate_request}}]
at com.mongodb.internal.connection.BaseCluster.createTimeoutException(BaseCluster.java:407)
at com.mongodb.internal.connection.BaseCluster.selectServer(BaseCluster.java:118)
at com.mongodb.internal.connection.AbstractMultiServerCluster.selectServer(AbstractMultiServerCluster.java:52)
at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:137)
at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:95)
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:266)
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:170)
at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:135)
at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92)
at de.visionvenue.statify.main.Main.lambda$3(Main.java:235)
at java.base/java.lang.Thread.run(Thread.java:834)
主线 233-235 号线
MongoCollection<Document> collection = MongoDBHandler.getDatabase().getCollection("statistics");
FindIterable<Document> iterDoc = collection.find();
Iterator<Document> it = iterDoc.iterator();
这是我连接到数据库的类
public class MongoDBHandler {
static MongoDatabase db;
public static void connect() {
try {
ConnectionString connString = new ConnectionString(
"mongodb+srv://[USERNAME]:[PASSWORD]@statify.st9vh.mongodb.net/[DATABASE]?retryWrites=true&w=majority");
MongoClientSettings settings = MongoClientSettings.builder().applyConnectionString(connString)
.retryWrites(true).build();
MongoClient mongoClient = MongoClients.create(settings);
MongoDatabase database = mongoClient.getDatabase("Database");
System.out.println("Connected to database");
db = database;
} catch (Exception ex) {
String error = ex.toString() + "\n";
for (int i = 0; i < ex.getStackTrace().length; i++) {
error = error + ex.getStackTrace()[i].toString() + "\n";
}
ReportManager.createInstantReport("MongoDB Connection", error);
}
}
public static MongoDatabase getDatabase() {
return db;
}
}
我替换了这篇文章的用户、密码和数据库。
我已经检查了两次。IP被列入白名单,连接服务器相同,用户名和密码正确。这段代码运行良好,但突然坏了。我没有更改可能导致此问题的与数据库相关的任何内容。
解决方案
我刚刚联系了 MongoDB 支持。他们告诉我这是 TLS 1.3 中的当前错误。我将 Java 版本更改为 8 并且它工作
官方错误报告可以在这里找到: https ://bugs.openjdk.java.net/browse/JDK-8236039
推荐阅读
- bash - bash / 检查数字是否与列表中的数字匹配
- java - 如何在 recycleView 中创建 CardView?
- r - 尝试对曲线下面积 (AUC) 进行积分,错误为“match.fun(f) 中的错误:'a1$iso' 不是函数、字符或符号”
- protocol-buffers - 无法在 ami linux2 上安装 mysql_xdevapi
- python - 如何在使用 Selenium Webdriver 查找元素时正确使用 '{}'.format()
- javascript - 错误:无法在控制台中读取 null 的属性“insertAdjacentHTML”
- unix - 无法在 cron 作业的脚本中记录 netcat 输出
- angular - 如何在 Angular Guard 中使用 CombineLatest 和 Ngrx
- jinja2 - 无法使 Salt 状态下的 IF OR Jinja 逻辑工作
- android - 错误:'E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher' 使用本机反应