gpt4 book ai didi

java - WritableServerSelector 没有从集群中选择服务器

转载 作者:可可西里 更新时间:2023-11-01 09:58:54 25 4
gpt4 key购买 nike

作为 MongoDB 的新手,我正在尝试将一个简单的文档插入到我新安装的 mongoDB (v3.2.4) 中。使用 MongoDB Driver 3.2.2。这是我最小化的代码:

public <classname>()
{
public static final String COLLECTION_NAME = "logs";
MongoClient mongoClient = new MongoClient("<server-adress>");
MongoDatabase db = mongoClient.getDatabase("test");

Document data = new Document ();
data.append(<whatever>);
//...inserting more into document...
db.getCollection(COLLECTION_NAME).insertOne(data); //collection should be created new

mongoClient.close();
}

程序正在执行,但我在执行期间收到以下错误(和信息):

Mär 16, 2016 3:50:06 PM com.mongodb.diagnostics.logging.JULLogger log
INFORMATION: Cluster created with settings {hosts=[<server-adress>:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
Mär 16, 2016 3:50:06 PM com.mongodb.diagnostics.logging.JULLogger log
INFORMATION: No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, all=[ServerDescription{address=<server-adress>:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
Mär 16, 2016 3:50:07 PM com.mongodb.diagnostics.logging.JULLogger log
INFORMATION: Exception in monitor thread while connecting to server <server-adress>:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
(...)
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
... 3 more

Error: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=<server-adress>:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]

文档也没有插入。

当我用 insertOne() 命令注释该行时,它消失了。所以我认为这不是连接问题,对吗?

我有一些想法:

  • 它与异步性有关吗?我会很惊讶,我在任何地方都没有说过我不想同步执行它。
  • 是否缺少任何权限(因为这个 WritableServerSelector-Thing)?
  • 它与“测试”数据库有关吗?
  • MongoDB 的单机模式有问题吗? (我不想使用副本集。)

但对于所有这些想法,我找不到真正的证据......

(请改进问题标题,我没有更好的主意......)

最佳答案

我自己解决了。

我还应该提到,我正在尝试从另一台机器连接到 MongoDB 实例。 MongoDB 预设不允许这样做。

所以我不得不在/etc/mongod.conf 文件中将 bindIp 后面的值从 127.0.0.1 更改为 0.0.0.0。

[Source]

关于java - WritableServerSelector 没有从集群中选择服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36039756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com