Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to listen only to localhost on MongoDB

MongoDB Suggests that the easy way to handle security is to run it in a trusted environment, given that, "in such a configuration, one must be sure only trusted machines can access database TCP ports."

What would be the best approach for doing this? Is there a way for mongodb to natively only listen to localhost?

I'm using ubuntu 10.10

like image 460
Stephen Avatar asked Feb 10 '11 18:02

Stephen


People also ask

How do I access MongoDB on localhost?

To connect to your local MongoDB, you set Hostname to localhost and Port to 27017 . These values are the default for all local MongoDB connections (unless you changed them). Press connect, and you should see the databases in your local MongoDB.

What is localhost exception in MongoDB?

The localhost exception allows you to enable access control and then create the first user or role in the system. After you enable access control, connect to the localhost interface and create the first user in the admin database. If you create a user first, the user must have privileges to create other users.

What is MongoDB localhost URL?

connect('mongodb://localhost:27017/myapp'); This is the minimum needed to connect the myapp database running locally on the default port (27017). If connecting fails on your machine, try using 127.0. 0.1 instead of localhost .

Can you host MongoDB locally?

Installing the MongoDB Community Server Edition allows us to host MongoDB databases locally unlike Atlas which is a cloud hosted database option.


2 Answers

Add the following line into mongodb.conf:

bind_ip = 127.0.0.1 

As @Josh Rickard stated in comments: don't forget to restart the process after updating the config file:

service mongodb restart 
like image 116
freedev Avatar answered Oct 09 '22 09:10

freedev


As Andreas mentioned in a round-about way:

mongod --bind_ip 127.0.0.1 
like image 43
Scott Hernandez Avatar answered Oct 09 '22 09:10

Scott Hernandez