Mongo Java Driver Failing to Connect to MongoD

56 views
Skip to first unread message

ajinkya prabhune

unread,
Nov 18, 2011, 12:11:32 PM11/18/11
to mongod...@googlegroups.com

Hello All,

I have a java project and am connecting to  mongod process using the following
code

                   private static Mongo mongoObj = null; 
                   private static DB db = null; 
                  
                   mongoObj = new Mongo("localhost", 27017 );
   db = mongoObj.getDB( "MyDataBase" );


I was using this code for the last 4months and have created thousands of documents but suddenly I am unable to connect to MongoD process.
But when I change from IP address to use "localhost" it works.


java.io.IOException: couldn't connect to [/"IPADDRESS OF THE MACHINE":27017] bc:java.net.Conne
ctException: Connection timed out: connect
        at com.mongodb.DBPort._open(DBPort.java:206)
        at com.mongodb.DBPort.go(DBPort.java:94)
        at com.mongodb.DBPort.go(DBPort.java:75)
        at com.mongodb.DBPort.findOne(DBPort.java:129)
        at com.mongodb.DBPort.runCommand(DBPort.java:138)
        at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java
:419)
        at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:406)
        at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:144)
        at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:137)
        at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:255)
        at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:210)
        at com.mongodb.DBCollection.insert(DBCollection.java:80)
       







-- 

Thank you and Regards
Ajinkya Prabhune

Brendan W. McAdams

unread,
Nov 18, 2011, 12:22:33 PM11/18/11
to mongod...@googlegroups.com
Are you running on Mac OS by chance?

There is a known issue (caused by an oddity in the code of how Java for Mac looks up network addresses) that makes "localhost" resolve to the PUBLIC IP of your machine rather than 127.0.0.1 … if your Mongo instance is only listening to 127.0.0.1, you'll get an issue along these lines.

Otherwise, check what interfaces your Mongo server is set to listen on.  Many distributions start up listening only on 127.0.0.1

Check that the startup option or config value bind_ip isn't set.

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

ajax

unread,
Nov 19, 2011, 4:58:02 AM11/19/11
to mongodb-user
Hi,

I am using Windows 7 OS.
And I am clueless why suddenly it has stopped.

Could you please let me know if this is a known issue ? and there is a
solution to it.


Thanks
Ajinkza

Eliot Horowitz

unread,
Nov 19, 2011, 5:51:33 PM11/19/11
to mongod...@googlegroups.com
Its probably a firewall or ip change on the machine.
Are you sure the ip is the same?

ajax

unread,
Nov 20, 2011, 9:33:19 AM11/20/11
to mongodb-user
HI,

Thanks for the suggestions..
But no the ip has not changed and neither the firewall settings...
But yes I updated my Windows7 version... Can that cause an issue ?

Thanks..
Ajinkya

Scott Hernandez

unread,
Nov 20, 2011, 9:41:36 AM11/20/11
to mongod...@googlegroups.com
Try connecting specifically to 127.0.0.1

Does that work well?

ajax

unread,
Nov 21, 2011, 5:27:37 AM11/21/11
to mongodb-user
Hi Scott,

Yes 127.0.0.1 works. But with the IP it fails
could you please let me know what might be the issue.

Thanks
Ajinkya

Nat

unread,
Nov 21, 2011, 5:31:18 AM11/21/11
to mongod...@googlegroups.com
Very likely that it's something to do with your firewall setting. Can you check whether you allow mongod.exe to listen to connections?

ajax

unread,
Nov 21, 2011, 11:59:30 AM11/21/11
to mongodb-user
Hi Nat,
Yes it works I added mongod.exe in the firewall allowed apps list and
it worked.Thanks a lot for ur help. :-) really appreciated
Cheers Ajinkya
Reply all
Reply to author
Forward
0 new messages