createUser in MongoDB

Login as normal user without password after your installation and create user as follow

use admin
db.createUser(
{
    user: "root",
    pwd: "root",
    roles: [
              { role: "userAdminAnyDatabase", db: "admin" },
              { role: "readWriteAnyDatabase", db: "admin" },
              { role: "dbAdminAnyDatabase", db: "admin" },
              { role: "clusterAdmin", db: "admin" }
           ]
})

There after restart your db as follow

sudo service mongod stop
sudo service mongod start

Then, can able to login with the username and password. if you are not able to login just restart your machine.

mongo --port 27017 -u "tom" -p "jerry" --authenticationDatabase "admin"