Open up mongodb config file:
Ubuntu:
sudo nano /etc/mongod.conf
Window:
MongoDB_installation_Directory/Server/{version}/bin/mongod.cfg
// MongoDB_installation_Directory could be C://MongoDB or C://Program Files/MongoDB
Edit:
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0 #default value is 127.0.0.1
Restart MongoDB Server:
sudo service mongod restart
By default mongodb is configured to allow connections only from localhost. We need to allow remote connections. In the config file, go to the network interfaces section and change the bindIp from 127.0.0.1
to 0.0.0.0
which means allow connections from all IP addresses.