MongoDB is easy enough to use that you don’t even have to think about adding user when start using it. This could lead to a problem down the road when you are need to open your database access to public internet. And also the provided free version do not support SSL!. But that is another issue.
For now, lets take note on how we can start adding user (and password) to protect our database access.
First you want to start add admin user which can manage other users
then in Mongo shell
1 2 3 4 5 6 7 8 9 10 11 12 13
Then exit shell by
Ctrl+C or type
Enable auth on MongoD
edit the mongo conf file with
Uncomment this line
If you want to access from other machine change the line
More protection is necessary in production servers. I will explore this later.
Then restart mongod
Add user to the database
Open Mongo shell
Add new database and its user
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
There you have it. Now your MongoDB is user-password protected. Its a small step but necessary.