Eyal Zinder
Eyal Zinder

Reputation: 664

Connect to MongoDB on Azure (from client)

I am trying to setup my MongoDB dev environment using Azure VM. The VM is up and running MongoDB 2.6.6, and I can SSH to the VM and run MongoDB just fine..

However, I am unable to connect to Mongo from any external client (i.e. cmd shell mongo client, or robomongo). I'm using the public IP given to me, and using the default port. I've also tried to edit the /etc/mongodb.conf to specify the port number (port=27017), and have restarted the service.. but that didn't seem to make a difference at all..

Upvotes: 3

Views: 6067

Answers (2)

David Makogon
David Makogon

Reputation: 71030

I'm assuming this will be moved to ServerFault. In the meantime: There are two things required for external access, if you just spun up a new MongoDB instance:

  1. In mongod.conf, the default configuration for bind_ip is 127.0.0.1, which means mongod is bound to the local interface. Comment out this line to listen on all interfaces
  2. Azure-specifically: Make sure you created an input endpoint to allow external traffic to reach the MongoDB VM. You can use any port for the external-facing side, and just have it map to 27017 internally. From a convention perspective, It makes sense to use 27017 both externally and internally, since that's the default MongoDB port.

Upvotes: 7

Gennadiy
Gennadiy

Reputation: 326

The port that mongodb uses is not open for external access. One way you can access it from the client is to open ssh tunnel. Default port for mongodb is 27017: ssh -f -L 27017::27017

Read more on ssh tunneling here: http://blog.trackets.com/2014/05/17/ssh-tunnel-local-and-remote-port-forwarding-explained-with-examples.html

Upvotes: 2

Related Questions