MongoDB provides a number of built-in roles. However, if these roles cannot describe the desired set of privileges, you can create new roles.MongoDB提供了许多内置角色。但是,如果这些角色无法描述所需的权限集,则可以创建新角色。
Note
You can configure custom database roles in the UI for deployments hosted in MongoDB Atlas. To learn more, see Configure Custom Database Roles.您可以在MongoDB Atlas中托管的部署的UI中配置自定义数据库角色。要了解更多信息,请参阅配置自定义数据库角色。
Role Management Interface角色管理界面
To add a role, MongoDB provides the 为了添加角色,MongoDB提供了db.createRole() method. MongoDB also provides methods to update existing user-defined roles. db.createRole()方法。MongoDB还提供了更新现有用户定义角色的方法。For a full list of role management methods, see Role Management.有关角色管理方法的完整列表,请参阅角色管理。
Scope作用域
When adding a role, you create the role in a specific database. MongoDB uses the combination of the database and the role name to uniquely define a role.添加角色时,您需要在特定数据库中创建角色。MongoDB使用数据库和角色名称的组合来唯一定义角色。
Except for roles created in the 除了在admin database, a role can only include privileges that apply to its database and can only inherit from other roles in its database.admin数据库中创建的角色外,角色只能包含适用于其数据库的权限,并且只能继承其数据库中的其他角色。
A role created in the 在admin database can include privileges that apply to the admin database, other databases or to the cluster resource, and can inherit from roles in other databases as well as the admin database.admin数据库中创建的角色可以包括应用于admin数据库、其他数据库或集群资源的权限,并且可以继承其他数据库以及admin数据库中的角色。
Centralized Role Data集中式角色数据
MongoDB stores all role information in the system.roles collection in the MongoDB将所有角色信息存储在admin databaseadmin数据库的system.roles集合中
Do not access this collection directly but instead use the role management commands to view and edit custom roles.不要直接访问此集合,而是使用角色管理命令查看和编辑自定义角色。