Share mongoDB in two droplets

January 11, 2016 3.9k views
Node.js MongoDB

I have two droplets and I want both of them to share the same MongoDB. Is it possible? I tried to get the MongoURL so I include it in both my meteor.js projects but I found no way to get it. I bet it’s quite easy.

I’d truly appreciate any help you can give me.

1 Answer

In order to enable access over the internet, modify the value of bind_ip in /etc/mongod.conf By default, it is set to which only allows local access. Changing the value to the IP address of your Droplet will allow external connections. Before doing so, please remember to review the MongoDB security checklist.

# network interfaces
  port: 27017

You will need to restart MongoDB for the changes to take effect:

  • sudo service mongod restart

In addition to enabling one of the forms of authentication supported by MongoDB, setting up a firewall that only allows remote connections from specific IP addresses is a good security measure to implement. On Ubuntu, you can do this with UFW. The following commands will setup a basic firewall which will allow all outgoing connections from your server but only allow incoming connections via SSH or from the specified IP address ( of your other server.

sudo apt-get install ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow from
sudo ufw enable

Using your Droplet’s private IP address is also a good idea.

by Shaun Lewis
Learn how to setup a firewall with UFW on an Ubuntu / Debian cloud server.
Have another answer? Share your knowledge.