Connect to remote mongodb server with java

exxodus7 picture exxodus7 · May 30, 2013 · Viewed 12.8k times · Source

I'm trying to connect to a remote mongodb instance, but it keeps throwing an error.

Java code:

Mongo mongo = new Mongo("172.234.52.24");
DB db = mongo.getDB("myDB");
collection = db.getCollection("myCollection");

But I keep getting the following exception:

java.io.IOException: couldn't connect to [/172.234.52.24:27017] bc:java.net.ConnectException: Connection refused

Is there something else I have to do? Set username/password when I try to access the database or change some permissions on the mongo side? Its just the normal mongo install on a ubuntu server, no added configuration or permissions.

ADDITIONAL INFORMATION: mongo 172.234.52.24:8888 doesn't work either, says exception: connect failed. I can ping the other host, and know mongo is running on it.

Any ideas? Thanks!

Answer

exxodus7 picture exxodus7 · May 30, 2013

I figured it out... y'all had great suggestions but the problem was more fundamental.

In my mongo configuration file on the remote server, there was a bind_ip variable set to the local ip. Once I commented this out, everything worked properly.

Thank you all very much though!