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