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"
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s