Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect my mongoDB database from my local machine

Tags:

mongodb

UPDATED:

I just start to deal with a new VPS and i am trying to connect its port 27017 (mongodb database) from localhost (using robomongo).

It's working on my localhost machine and with another remote server, but i can't connect mongodb on this VPS, what could cause this issue ? I start it this way:

mongod --setParameter enableLocalhostAuthBypass=0 --config /etc/mongodb.conf --fork

with the auth = true uncommented in the /etc/mongodb.conf file (but it looks like the issue is not that i can't auth but mongodb is not responding at all). When i start mongo admin -u root -p root by being connected with SSH, it works great (i can connect my database) and i can see that mongodb is well listenning on the port 27017.

But when i try to access it from my local machine, it can't establish the connection, and if i try to connect it with my browser, i am supposed to get a mongodb error message: You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number but i don't, i just have a failure page with Chrome (and the port 28017 is not responding either).

How to solve this ? My VPS is brand new and i could need to install more packages but i really don't see what could be need for this, it also looks like a firewall issue, like something prevent mongodb and response before the request could reach it, i have juste installed apache2 and nginx and they are not running so i really don't see...

like image 824
Ludo Avatar asked Apr 01 '14 19:04

Ludo


1 Answers

Ok, I have found the issue!

There is a line bind_ip 127.0.0.1 in the /etc/mongod.conf file. It provides access only to the specified IP address to mongodb.

You should create an array of IPs and edit the config file as:

bind_ip [127.0.0.1, x.x.x.x, ...]

Where x.x.x.x is your IP.

like image 96
Ludo Avatar answered Sep 30 '22 05:09

Ludo