MongoDB Setting up an admin and login as admin

Yasiru Nilan
1 min readFeb 17, 2017

--

Log in to your mongoDB console typing

$ mongo

After that let’s use the admin database and create an admin user role.

>db.createUser(
{
user: "admin",
pwd: "password",
roles: [ { role: "root", db: "admin" } ]
}
);

Then exit the mongoDB shell using,

>exit;

Again log in to mongo shell, use following commands to log in as the admin.

>use admin
>db.auth('admin','password');

--

--