【问题标题】:MongoTimeoutException: Error While Using MongoDB with TrinoMongoTimeoutException:将 MongoDB 与 Trino 一起使用时出错
【发布时间】:2021-06-10 10:07:04
【问题描述】:

我将 mongodb.properties 传递为

connector.name=mongodb mongodb.seeds=127.0.0.1:27017 mongodb.credentials=username:password@database

但是在通过查询后运行目录时,它会给出错误

Query 20210312_110147_00003_zxyd4 failed: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@469d4507. Client view of cluster state is {type=REPLICA_SET, servers=[{address=hostname:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]

有人可以帮忙吗?连接时我做错了吗?

注意:- 我在本地运行 trino,使用单台机器进行测试,它既是协调器又是工作器,而 mongodb 在其他服务器上,但我正在将 localhost 路由到所需的使用 ssh 的服务器

【问题讨论】:

  • 您是否确认可以使用相同的配置连接 MongoDB Compass 或其他客户端?
  • 是的,我在 robo3T 中尝试过使用相同的配置。它正在工作

标签: mongodb presto trino


【解决方案1】:

在使用这个 JAVA 代码时可以工作,使用这两个 mongodb-driver-core-3.7.1-javadoc.jar,mongo-java-driver-3.3.0.jar 文件来编译和在代码下面运行

import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import java.util.Collections;
import org.bson.Document;
import java.util.List;

public class MongoSession
{
    public static void main(String[] args)
    {
        ServerAddress seed = new ServerAddress("127.0.0.1:27017");
        MongoCredential credential = MongoCredential.createCredential("user", "database", "password".toCharArray());
        MongoClient client = new MongoClient(seed, Collections.singletonList(credential), MongoClientOptions.builder().build());
        client.getDatabase("database").runCommand(new Document("ping", 1));
        for (String name : client.getDatabase("database").listCollectionNames()) {
            System.out.println(name);
        }
    }
}

感谢 MongoDB 社区的快速响应

吉拉:- https://jira.mongodb.org/browse/JAVA-4076?focusedCommentId=3673048&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-3673048

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    • 2016-11-05
    • 2021-12-06
    • 2015-07-15
    • 2016-05-04
    • 2014-02-10
    • 2016-04-03
    相关资源
    最近更新 更多