i'm trying to connect my spring boot app to a remote mongodb database. When i run my app i got this error:
2017年05月25日 15:22:57.829 INFO 4532 --- [*******:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server mongodb-server-address:27017
com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.4.2.jar:na] at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongodb-driver-core-3.4.2.jar:na] at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) ~[mongodb-driver-core-3.4.2.jar:na] at java.lang.Thread.run(Unknown Source) [na:1.7.0_79] Caused by: java.net.ConnectException: Connection refused: connect
1 Answer 1
By default MongoDB only binds to the loopback interface which makes it only accessible from localhost. To change that you need to edit this line in mongod.conf file;
you can change it to allow LAN and local connections or you can remove or comment out that line bind_ip = 127.0.0.1 to allow all connections.
For more info : MongoDB – Allow remote access