31 RoleNotFound: Role not found(未找到角色)
MongoDB含义
所引用的角色未在 MongoDB 中定义。在向用户授予角色、更新角色或查询角色权限时使用了不存在的角色名。
原因
grantRolesToUser/createUser 中的角色名拼写错误或从未创建;在错误的数据库中查找角色(角色绑定到特定 DB);或自定义(非内置)角色尚未用 createRole 定义。
解决方法
确认角色名及其所属数据库。列出现有角色:db.getRoles({showBuiltinRoles: false}) 或在所有 DB 上执行相应的管理查询。如果自定义角色不存在,先创建:db.createRole({role:'reader', privileges:[...], roles:[]})。授予时指定正确的 db:db.grantRolesToUser('app_user', [{role:'reader', db:'app'}])。
同一数据库的其他条目
- 9FailedToParse
- 134ReadConcernMajorityNotAvailableYet
- 202NetworkInterfaceExceededTimeLimit
- 263 OperationNotSupportedInTransactionOperation not supported inside a multi-document transaction(多文档事务中不支持该操作)
- 20 IllegalOperationIllegal operation(非法操作)
- 48 NamespaceExistsNamespace (collection) already exists(命名空间(集合)已存在)
- 11601 InterruptedOperation was interrupted(操作被中断)