I am unable to connect to my MongoDB instance from my Java client. The MongoDb instance is installed on a Ubuntu VM session inside VirtualBox. Mongo works fine when I run commands from the Mongo shell within Ubuntu - but I cant connect to it from my Windows 7 Intellij session.
My Java client code is as follows,
package com.mycom.mongodb.demo;
import com.mongodb.MongoClient;
public class App
{
public static void main( String[] args )
{
MongoClient mongoClient = new MongoClient("192.168.171.68", 27017);
mongoClient.getDatabaseNames().forEach(System.out::println);
}
}
But I get the error message shown below.
I am able to Ping the IP address of my Ubuntu box but I am not able to telnet to the IP:Port that MongoDb is running on.
this is my mongo.cfg file
MongoDb is running on LocalHost on the Ubuntu machine - so maybe this is an area that I need to configure ? Any help would be appreciated.
This is my command-line to start mongod
sudo /opt/mongodb/mongodb-linux-x86_64-ubuntu1604-3.6.3/bin/mongod --config /var/opt/mongodb2/mongo.cfg
UPDATE: I am able to get it working if I include the "--bind_ip_all" parameter i.e.
sudo /opt/mongodb/mongodb-linux-x86_64-ubuntu1604-3.6.3/bin/mongod --bind_ip_all --config /var/opt/mongodb2/mongo.cfg
which I guess is ok for a small demo program but not as a permanent solution