List collections failed: not authorized(Mongodb)

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.

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Comment

Scroll to Top