User-Defined Roles用户定义的角色

On this page本页内容

MongoDB provides a number of built-in roles.MongoDB提供了许多内置角色However, if these roles cannot describe the desired set of privileges, you can create new roles.但是,如果这些角色无法描述所需的权限集,则可以创建新角色。

Role Management Interface角色管理界面

To add a role, MongoDB provides the db.createRole() method.为了添加角色,MongoDB提供db.createRole()方法。MongoDB also provides methods to update existing user-defined roles.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 admin databaseMongoDB将所有角色信息存储在管理数据库中的system.roles集合中。

Do not access this collection directly but instead use the role management commands to view and edit custom roles.不要直接访问此集合,而是使用角色管理命令查看和编辑自定义角色。