Question

Can't connect MongoDB via Shared Private Networking

  • Posted on April 14, 2014
  • mickeyAsked by mickey

Hi,

I’ve setup a droplet with Shared Private Networking enabled. I’ve provisioned it with Ubuntu 12.10 x64. Also, I’ve installed mongodb using ‘sudo apt-get install mongodb’ command.

I tried using mongoose to connect to the mongodb droplet using the default port. It said failed to connect.

I used the command below:

var mongoose = require(‘mongoose’); mongoose.connect(‘mongodb://XXX.XXX.XXX.XXX:27017/database’);

Things I’ve tried…

  1. Ping the MongoDB droplet from the app droplet. It works.
  2. Ran ‘mongo’ command on the MongoDB droplet. It works.
  3. Ran ‘sudo netstat -plunt’ and saw the mongod process listening on the 27017 port.

Any idea what I could try to verify it or what I can do to resolve this?

Cheers, Mickey


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi, I am having the same problem. I have added the rule on IPTables and also set the bind_ip to 0.0.0.0 but always fail to connect.

What else do I need to check to pinpoint the problem?

I also recommend adding an IPTables rule that drops all packets to the MongoDB ports on the eth0 interface: <br><pre>sudo iptables -A INPUT -p tcp -m tcp -i eth0 --dport 27017 -j DROP</pre>

It solved. The bind_ip is set to 127.0.0.1 by default. Need to change it to 0.0.0.0. Cheers.