我将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在其他服务器上,但我使用ssh 将localhost路由到所需的服务器
它在使用此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社区提供了这样一个快速响应
Jira:-https://jira.mongodb.org/browse/JAVA-4076?focusedCommentId=3673048&page=com.atlassian.jira.plugin.system.issuetabpanels:comment tabpanel#comment-3673048