On this page本页内容
rolesInfo
Returns inheritance and privilege information for specified roles, including both user-defined roles and built-in roles.返回指定角色的继承和权限信息,包括用户定义角色和内置角色。
The rolesInfo
command can also retrieve all roles scoped to a database.rolesInfo
命令还可以检索数据库范围内的所有角色。
To match a single role on the database, use the following form:要匹配数据库中的单个角色,请使用以下表单:
{ rolesInfo: { role: <name>, db: <db> }, showPrivileges: <Boolean>, showBuiltinRoles: <Boolean>, comment: <any> }
rolesInfo
has the following fields:具有以下字段:
rolesInfo | string, document, array, or integer | |
showPrivileges | boolean | true to show role privileges, including both privileges inherited from other roles and privileges defined directly. true 以显示角色权限,包括从其他角色继承的权限和直接定义的权限。 |
showBuiltinRoles | boolean | rolesInfo field is set to 1 , set showBuiltinRoles to true to include built-in roles in the output. rolesInfo 字段设置为1 时,将showBuiltinRoles 设置为true 以在输出中包含内置角色。false , and the output for rolesInfo: 1 displays only user-defined roles. false ,rolesInfo:1 的输出仅显示 用户定义的角色。 |
comment | any |
|
To specify a role from the current database, specify the role by its name:要从当前数据库中指定角色,请通过其名称指定角色:
{ rolesInfo: "<rolename>" }
To specify a role from another database, specify the role by a document that specifies the role and database:要从其他数据库指定角色,请通过指定角色和数据库的文档指定角色:
{ rolesInfo: { role: "<rolename>", db: "<database>" } }
To specify multiple roles, use an array. 要指定多个角色,请使用数组。Specify each role in the array as a document or string. Use a string only if the role exists on the database on which the command runs:将数组中的每个角色指定为文档或字符串。仅当运行命令的数据库上存在角色时,才使用字符串:
{ rolesInfo: [ "<rolename>", { role: "<rolename>", db: "<database>" }, ... ] }
To specify all roles in the database on which the command runs, specify 要指定运行命令的数据库中的所有角色,请指定rolesInfo: 1
. rolesInfo:1
。By default MongoDB displays all the user-defined roles in the database. 默认情况下,MongoDB显示数据库中所有用户定义的角色。To include built-in roles as well, include the parameter-value pair 要同时包含内置角色,请包含参数值对showBuiltinRoles: true
:showBuiltinRoles:true
:
{ rolesInfo: 1, showBuiltinRoles: true }
To view a role's information, you must be either explicitly granted the role or must have the 若要查看角色的信息,必须明确授予该角色,或者必须对角色的数据库执行viewRole
action on the role's database.viewRole
操作。
rolesInfo.db
The database on which the role is defined. Every database has built-in roles. 在其上定义角色的数据库。每个数据库都有内置角色。A database might also have user-defined roles.数据库也可能具有用户定义的角色。
rolesInfo.isBuiltin
A value of 值true
indicates the role is a built-in role. true
表示该角色是内置角色。A value of 值false
indicates the role is a user-defined role.false
表示该角色是用户定义的角色。
rolesInfo.roles
The roles that directly provide privileges to this role and the databases on which the roles are defined.直接为该角色提供权限的角色以及在其上定义角色的数据库。
rolesInfo.inheritedRoles
All roles from which this role inherits privileges. 此角色从中继承权限的所有角色。This includes the roles in the 这包括rolesInfo.roles
array as well as the roles from which the roles in the rolesInfo.roles
array inherit privileges. rolesInfo.roles
数组中的角色以及rolesInfo.roles
数组中角色从中继承权限的角色。All privileges apply to the current role. 所有权限都适用于当前角色。The documents in this field list the roles and the databases on which they are defined.此字段中的文档列出了角色及其定义的数据库。
rolesInfo.privileges
The privileges directly specified by this role; i.e. the array excludes privileges inherited from other roles. 此角色直接指定的权限;即,数组排除从其他角色继承的权限。By default the output does not include the 默认情况下,输出不包括privileges
field. privileges
字段。To include the field, specify 要包含该字段,请在运行showPrivileges: true
when running the rolesInfo
command.rolesInfo
命令时指定showPrivileges:true
。
Each privilege document specifies the resources and the actions allowed on the resources.每个权限文档都指定了资源和资源上允许的操作。
rolesInfo.inheritedPrivileges
All privileges granted by this role, including those inherited from other roles. 此角色授予的所有权限,包括从其他角色继承的权限。By default the output does not include the 默认情况下,输出不包括inheritedPrivileges
field. To include the field, specify showPrivileges: true
when running the rolesInfo
command.inheritedPrivileges
字段。要包含该字段,请在运行rolesInfo
命令时指定showPrivileges:true
。
Each privilege document specifies the resources and the actions allowed on the resources.每个权限文档都指定了资源和资源上允许的操作。
The following command returns the role inheritance information for the role 以下命令返回associate
defined in the products
database:products
数据库中定义的角色associate
的角色继承信息:
db.runCommand( { rolesInfo: { role: "associate", db: "products" } } )
The following command returns the role inheritance information for the role 以下命令返回运行该命令的数据库上角色siteManager
on the database on which the command runs:siteManager
的角色继承信息:
db.runCommand( { rolesInfo: "siteManager" } )
The following command returns both the role inheritance and the privileges for the role 以下命令返回associate
defined on the products
database:products
数据库中定义的角色associate
的角色继承和权限:
db.runCommand( { rolesInfo: { role: "associate", db: "products" }, showPrivileges: true } )
The following command returns information for two roles on two different databases:以下命令返回两个不同数据库上两个角色的信息:
db.runCommand( { rolesInfo: [ { role: "associate", db: "products" }, { role: "manager", db: "resources" } ] } )
The following returns both the role inheritance and the privileges:下面将返回角色继承和权限:
db.runCommand( { rolesInfo: [ { role: "associate", db: "products" }, { role: "manager", db: "resources" } ], showPrivileges: true } )
The following operation returns all user-defined roles on the database on which the command runs and includes privileges:以下操作返回运行该命令的数据库上的所有用户定义角色,包括权限:
db.runCommand( { rolesInfo: 1, showPrivileges: true } )
The following operation returns all roles on the database on which the command runs, including both built-in and user-defined roles:以下操作返回运行命令的数据库上的所有角色,包括内置角色和用户定义角色:
db.runCommand( { rolesInfo: 1, showBuiltinRoles: true } )