Navigation
This version of the documentation is archived and no longer supported.

db.getRole()

Definition

db.getRole(rolename, showPrivileges)

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 takes the following arguments:

Parameter Type Description
rolename string The name of the role.
showPrivileges document Optional. If true, returns the role’s privileges. Pass this argument as a document: {showPrivileges: true}.

db.getRole() wraps the rolesInfo command.

Required Access

To view a role’s information, you must be 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:

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 } )