MongoTimeoutException:无服务器匹配 - MongoDB Atlas [英] MongoTimeoutException: No Server Match - MongoDB Atlas

查看:91
本文介绍了MongoTimeoutException:无服务器匹配 - MongoDB Atlas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在有几天了,我无法连接到由 Altas 托管的任何 MongoDB 数据库.我总是收到 MongoTimeoutException

For a few days now, I can't connect to any of my MongoDB Databases that are hosted by Altas. I'm always getting a 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)

Main 中的第 233-235 行

Line 233-235 in Main

MongoCollection<Document> collection = MongoDBHandler.getDatabase().getCollection("statistics");
FindIterable<Document> iterDoc = collection.find();
Iterator<Document> it = iterDoc.iterator();

这是我连接到数据库的类

Here is the class where I connect to the Database

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;
    }
}

我为这篇文章替换了用户、密码和数据库.

I replaced the user, password and database for this post.

我已经检查了两次.IP白名单,连接服务器相同,用户名密码正确.这段代码运行良好,但突然中断了.我没有更改与数据库相关的任何可能导致此问题的内容.

I already checked everything twice. The IP is whitelisted, the connection server is the same, username and password are correct. This code worked fine, but suddenly broke. I haven't changed anything releated to the Database that could cause this issue.

推荐答案

我刚刚联系了 MongoDB 支持.他们告诉我这是 TLS 1.3 中的当前错误.我将 Java 版本更改为 8 并且它起作用了

I just contacted the MongoDB Support. They told me that this is a current bug in TLS 1.3. I changed the Java Version to 8 and it worked

官方错误报告可以在这里找到:https://bugs.openjdk.java.net/browse/JDK-8236039

The official Bug Report can be found here: https://bugs.openjdk.java.net/browse/JDK-8236039

这篇关于MongoTimeoutException:无服务器匹配 - MongoDB Atlas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆