Error content
Com.mongodb.MongoTimeoutException:Timed out after 30000 MS and waiting for a server that matches Readpreferenceserverse Lector{readpreference=primary}. Client view of cluster state is {type=unknown, servers=[{address=127.0.0.1:27017, Type=unknown, state=connecting, Exception={com.mongodb.mongosocketopenexception:exception opening Socket}, caused by {java.net.ConnectException: Connection Refused:connect}}]
This means that the connection is not successful, 127.0.0.1 this is local, but the IP 192.168.xx.xx of the Linux virtual machine
So the Linux connection is not the same as the Java connection, all to the same IP.
1. If Linux is not set to IP, the default is 127.0.0.1, but the Linux IP is not this, all Java connections are not
The solution is to set the MongoDB boot IP to LINUXIP
1. When you start, you can add IP--bind_ip=192.168.88.134 directly to the rear.
/home/mongodb/bin/mongod--fork--bind_ip=192.168.88.134--dbpath=/home/mongodb/data/db--logpath=/home/mongodb/ Data/log/mongodb.log--logappend
2. Create a mongodb.conf file yourself, put the values to be set inside, I only put a few major tests
# log file location logpath=/usr/local/server/mongodb/logs# write to log logappend=true# as a daemon run fork = true# default 27017port = 27017# Database file location Dbpath=/usr/local/server/mongodb/data#ip address bind_ip = 127.0.0.1
The configuration file will be added to boot.
./mongod--config/usr/local/server/mongodb/mongodb.conf
Java Connection MongoDB Error resolution