2
通过WritableServerSelector选择作为一个新手,没有服务器到MongoDB中,我试图插入一个简单的文件到我新安装的MongoDB(V3.2.4)。使用MongoDB驱动程序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();
}
的PROGRAMM正在执行,但在执行过程中,我发现了以下错误(和信息):
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()行 - 命令,它就会消失。所以我认为这不是连接问题,对吗?
我有一些想法:
- 它有事情做与asynchronity?我会被高估,我没有说我不想同步执行它。
- 是否有任何权限丢失(因为这
WritableServerSelector
-Thing的)? - 它与“测试”数据库有关吗?
- MongoDB的独立模式有问题吗? (我不希望使用replicasets。)
但所有这些想法我无法找到真正的证据......
(请提高的问题标题,我没有更好的主意。 ..)
很好的回答,它救了我的时间:)我可以在这里补充,另一个选项来指定bindIp是命令行参数,这样的: 'mongod的--bind_ip = 0.0.0.0' 谢谢! –