- Reference >
- Database Commands >
- Role Management Commands >
- rolesInfo
rolesInfo¶
On this page
Definition¶
-
rolesInfo¶ Returns inheritance and privilege information for specified roles, including both user-defined roles and built-in roles.
The
rolesInfocommand can also retrieve all roles scoped to a database.To match a single role on the database, use the following form:
rolesInfohas the following fields:Field Type Description rolesInfostring, document, array, or integer The role(s) to return information about. For the syntax for specifying roles, see Behavior. 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.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.
Behavior¶
Return Information for a Single Role¶
To specify a role from the current database, specify the role by its name:
To specify a role from another database, specify the role by a document that specifies the role and database:
Return Information for Multiple Roles¶
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:
Return Information for All Roles in the Database¶
To specify all roles in the database on which the command runs, specify
rolesInfo: 1. By default MongoDB displays all the user-defined roles in the database. To include built-in roles as well, include the parameter-value pair
showBuiltinRoles: true:
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.
Output¶
-
rolesInfo.role¶ The name of the role.
-
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
trueindicates the role is a built-in role. A value offalseindicates the role is a user-defined role.
-
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.rolesarray as well as the roles from which the roles in therolesInfo.rolesarray inherit privileges. 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
privilegesfield. To include the field, specifyshowPrivileges: truewhen running therolesInfocommand.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
inheritedPrivilegesfield. To include the field, specifyshowPrivileges: truewhen running therolesInfocommand.Each privilege document specifies the resources and the actions allowed on the resources.
Examples¶
View Information for a Single Role¶
The following command returns the role inheritance information for the
role associate defined in the products database:
The following command returns the role inheritance information for the role
siteManager on the database on which the command runs:
The following command returns both the role inheritance and the privileges
for the role associate defined on the products database:
View Information for Several Roles¶
The following command returns information for two roles on two different databases:
The following returns both the role inheritance and the privileges:
View All User-Defined Roles for a Database¶
The following operation returns all user-defined roles on the database on which the command runs and includes privileges:
View All User-Defined and Built-In Roles for a Database¶
The following operation returns all roles on the database on which the command runs, including both built-in and user-defined roles: