DBAtlas · Database operations atlas

31 RoleNotFound: Role not found

MongoDB

What does it mean?

The referenced role is not defined in MongoDB. A nonexistent role name was used while granting a role to a user, updating a role or querying a role's privileges.

Why does it happen?

A misspelled or never-created role name in grantRolesToUser/createUser; looking up the role in the wrong database (roles are bound to a specific DB); or a custom (non-built-in) role that has not yet been defined with createRole.

How to fix it

Verify the role name and the database it belongs to. List existing roles: db.getRoles({showBuiltinRoles: false}) or the corresponding admin query across all DBs. If the custom role does not exist, create it first: db.createRole({role:'reader', privileges:[...], roles:[]}). Specify the correct db when granting: db.grantRolesToUser('app_user', [{role:'reader', db:'app'}]).

Open in DBAtlas →

More from this engine