User-Defined Roles用户定义的角色
On this page本页内容
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提供了许多内置角色。但是,如果这些角色无法描述所需的权限集,则可以创建新角色。
Role Management Interface角色管理界面
To add a role, MongoDB provides the 为了添加角色,MongoDB提供了db.createRole()
method. db.createRole()
方法。MongoDB also provides methods to update existing user-defined roles. For a full list of role management methods, see Role Management.MongoDB还提供了更新现有用户定义角色的方法。有关角色管理方法的完整列表,请参阅角色管理。
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将system.roles集合中的所有角色信息存储在admin
databaseadmin
数据库中
Do not access this collection directly but instead use the role management commands to view and edit custom roles.不要直接访问此集合,而是使用角色管理命令来查看和编辑自定义角色。