db.getRole()
Definition
db.
getRole
(rolename, args)- Returns the roles from which this role inherits privileges. Optionally, themethod can also return all the role’s privileges.
Run db.getRole()
from the database that contains the role. Thecommand can retrieve information for both user-defined roles and built-in roles.
The db.getRole()
method accepts the following parameters:
ParameterTypeDescriptionrolename
stringThe name of the role.args
documentOptional. A document specifying additional arguments.
The args
document supports the following fields:
FieldTypeDescriptionshowBuiltinRoles
booleanOptional. When the rolesInfo
field is set to 1
, set showBuiltinRoles
totrue
to include built-in roles in the output.By default this field is set to false
, and the output for rolesInfo:1
displays only user-defined roles.showPrivileges
booleanOptional. Set the field to true
to show role privileges, including both privilegesinherited from other roles and privileges defined directly. By default, thecommand returns only the roles from which this role inherits privileges anddoes not return specific privileges.
db.getRole()
wraps the rolesInfo
command.
Required Access
To view a role’s information, you must be either explicitly granted therole or must have the viewRole
action on the role’s database.
Examples
The following operation returns role inheritance information for the roleassociate
defined on the products
database:
- use products
- db.getRole( "associate" )
The following operation returns role inheritance information _and privileges_for the role associate
defined on the products
database:
- use products
- db.getRole( "associate", { showPrivileges: true } )