com.mongodb.MongoSocketOpenException: Exception opening socket???
远程连接MongoDB出现连接不上的情况如下:
Exception in thread "main" com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN,servers=[{address=192.168.142.198:27017,type=UNKNOWN,state=CONNECTING,exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}] com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:369)com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101)com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.(ClusterBinding.java:75)com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource(ClusterBinding.java:71)com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68)com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:158)com.mongodb.operation.
解决方法:将配置文件mongodb.conf中,bind_id=127.0.0.1改为bind_id=0.0.0.0 再重启服务