When you get the above error while accessing the Mongodb, you can simply resolve it by changing the role.

You need to 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’ } ]
}
);

If you have already created the admin user, you can change the role like this:

use admin;
db.grantRolesToUser(‘admin’, [{ role: ‘root’, db: ‘admin’ }])

Now try to access the collection, you can view the list with out any issues.

Leave a Reply

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny