- Reference >
mongoShell Methods >- Role Management Methods >
- db.getRole()
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. The command can retrieve information for both user-defined roles and built-in roles.The
db.getRole()method accepts the following parameters:Parameter Type Description rolenamestring The name of the role. argsdocument Optional. A document specifying additional arguments. The
argsdocument supports the following fields:Field Type Description showBuiltinRolesboolean Optional. When the rolesInfofield is set to1, setshowBuiltinRolestotrueto include built-in roles in the output. By default this field is set tofalse, and the output forrolesInfo: 1displays only user-defined roles.showPrivilegesboolean Optional. Set the field to trueto show role privileges, including both privileges inherited from other roles and privileges defined directly. By default, the command returns only the roles from which this role inherits privileges and does not return specific privileges.db.getRole()wraps therolesInfocommand.
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.
Examples¶
The following operation returns role inheritance information for the role
associate defined on the products database:
The following operation returns role inheritance information and privileges
for the role associate defined on the products database: