有几天,我无法连接到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为白名单,连接服务器相同,用户名和密码正确。这个代码工作得很好,但突然坏了。我没有更改任何可能导致此问题的与数据库相关的内容。
1条答案
按热度按时间cyej8jka1#
我刚联系了mongodb的支持人员。他们告诉我这是TLS1.3中的一个当前错误。我把java版本改成了8,它成功了
官方的错误报告可以在这里找到:https://bugs.openjdk.java.net/browse/jdk-8236039