Follow below steps to enable authentication in MongoDB.

1- Run command

 praveen@acer-aspire:~# gedit /etc/mongodb.conf 

add ‘auth=true’ or uncomment by removing # it if exists.

2- Add atleast one user to the DB ‘admin’ .

Admin user can access all the collections in the DB.

You can also add users to other DBs.

> use admin

> db.addUser(“testuser “,”testpassword”);

> db.addUser(“testuser “,”testpassword”,true) //read only user

> db.system.users.find(); //This will show lists the users in the Db

> db.removeUser(“testuser”); //If you want to remove a user 

3- Now Restart MongoDB using following command

 praveen@acer-aspire:~# restart mongodb

4- Now access the mongodb console and login.

 praveen@acer-aspire:~# mongo

> use admin

> db.auth(“testuser”,”testpassword”); // return 1 on success or else 0.

5- After authentication you can use the DB .

Note : once you enable authentication mode you will have to login using user name and password to use DBs.