Error reported when Java connects mongodb com.mongodb.mongosocketopenexception: exception opening socket has been solved

Using idea to write java connection mongodb to report an error, let’s take a look at the detailed error information first

Solutions

Editor

vim mongodb/conf/mongod.conf

Add

bind_ip=0.0.0.0

After modification, the configuration file is as follows:

#Specify the start port
port=27017
#Specify the data storage directory
dbpath=data/db
#Specify the log storage directory
logpath=log/mongodb.log
#Run in the background
fork=true
#Log in with any IP
bind_ip=0.0.0.0

Causes of error information

Since mongodb version 3.6, it has_ The value of IP is localhost by default, so you can only use localhost to log in

Just change its IP to 0.0.0.0, you can use any IP login

Similar Posts: