DEV Community

loading...

Answer: MongoDB - admin user not authorized

rnagarajan96 profile image Nagarajan R ・1 min read

I was also scratching my head around the same issue, and everything worked after I set the role to be root when adding the first admin user.

use admin
db.createUser(
  {
    user: 'admin',
    pwd: 'password',
    roles: [ { role: 'root', db: 'admin' } ]
  }
);
exit;

If you have…

Discussion

pic
Editor guide