db.getRole()

On this page本页内容

Definition定义

db.getRole(rolename, args)

Returns the roles from which this role inherits privileges. 返回此角色从中继承权限的角色。Optionally, the method can also return all the role’s privileges.或者,该方法还可以返回角色的所有权限。

Run db.getRole() from the database that contains the role. 从包含该角色的数据库中运行db.getRole()The command can retrieve information for both user-defined roles and built-in roles.该命令可以检索用户定义角色内置角色的信息。

The db.getRole() method accepts the following parameters:db.getRole()方法接受以下参数:

Parameter参数Type类型Description描述
rolename string The name of the role.角色的名称。
args document Optional.可选。A document specifying additional arguments.指定附加参数的文件。

The args document supports the following fields:args文档支持以下字段:

Field字段Type类型Description描述
showBuiltinRoles boolean Optional.可选。When the rolesInfo field is set to 1, set showBuiltinRoles to true to include built-in roles in the output. rolesInfo字段设置为1时,将showBuiltinRoles设置为true,以在输出中包含内置角色。By default this field is set to false, and the output for rolesInfo: 1 displays only user-defined roles.默认情况下,此字段设置为falserolesInfo: 1的输出仅显示用户定义的角色
showPrivileges boolean Optional.可选。Set the field to true to show role privileges, including both privileges inherited from other roles and privileges defined directly. 将该字段设置为true以显示角色权限,包括从其他角色继承的权限和直接定义的权限。By default, the command returns only the roles from which this role inherits privileges and does not return specific privileges.默认情况下,该命令只返回该角色从中继承权限的角色,而不返回特定权限。

db.getRole() wraps the rolesInfo command.包装rolesInfo命令。

Required Access所需访问权限

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操作

Examples示例

The following operation returns role inheritance information for the role associate defined on the products database:以下操作返回products数据库中定义的角色associate继承信息:

use products
db.getRole( "associate" )

The following operation returns role inheritance information and privileges for the role associate defined on the products database:以下操作返回products数据库中定义的角色associate的继承信息和权限

use products
db.getRole( "associate", { showPrivileges: true } )