Enabling and disabling remote access to a MongoDB Server

December 21, 2012
By

In MongoDB, the remote access is enabled by default. Remote access to MongoDB server can be controlled by the variable “bind_ip” specified in the configuration file mongodb.conf.

In MongoDB, the variable “bind_ip” is not set. So a MongoDB client, accessed from any remote machine can be connected to the MongoDB server by default.

The information provided in this article is tested with MongoDB 2.2.2 in Ubuntu 12.04 LTS.


Disabling remote access ( Localhost only access ) to MongoDB Server

  • OpenĀ  the file mongodb.conf and add the line bind_ip = 127.0.0.1
  • Restart MongoDB service [ In Ubuntu : $sudo service mongodb restart ]
  • Now remote access is disabled

Testing remote access to MongoDB Server

Installing MongoDB client in remote machine ( Ubuntu 12.04 )

$sudo apt-get install mongodb-clients

Connecting to MongoDB server from remote machine

ubuntu@node6:~$ mongo --host 192.168.1.3
MongoDB shell version: 2.0.4
connecting to: 192.168.1.3:27017/test
Fri Dec 21 11:15:48 Error: couldn't connect to server 192.168.1.3:27017 shell/mongo.js:86
exception: connect failed

Note : Success, remote access is failed


Enabling remote access to MongoDB Server

  • OpenĀ  the file mongodb.conf and comment the line containing the variable bind_ip
  • Restart MongoDB service [ In Ubuntu : $sudo service mongodb restart ]
  • Now remote access is enabled

Testing remote access to MongoDB Server

Connecting to MongoDB server from remote machine

ubuntu@node6:~$ mongo --host 192.168.1.3
MongoDB shell version: 2.0.4
connecting to: 192.168.1.3:27017/test
> db.version()
2.2.2

Note : Success, remote access is enabled


How to hire me?

I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to info@wptrafficanalyzer.in.

My other blogs
store4js.blogspot.com


Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :



Tags: , , , , ,

One Response to Enabling and disabling remote access to a MongoDB Server

  1. Sneha on December 8, 2015 at 3:15 pm

    Hi,

    Is it need to install mongo client?

    in my machine i have used ubuntu 12.04. I didn’t find any bind_ip inside my etc/mongodb.conf.

    is it necessary to config this file explicitly

Leave a Reply to Sneha Cancel reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner