db.getRoles()
On this page
This version of the documentation is archived and no longer supported. View the current documentation to learn how to upgrade your version of MongoDB server.
Definition
db.getRoles()
Returns information for all the roles in the database on which the command runs. The method can be run with or without an argument.
If run without an argument,
db.getRoles()
returns inheritance information for the database's user-defined roles.To return more information, pass the
db.getRoles()
a document with the following fields:FieldTypeDescriptionrolesInfo
integerSet this field to1
to retrieve all user-defined roles.showPrivileges
booleanOptional. Set the field totrue
to 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.showBuiltinRoles
booleanOptional. Set to true to display built-in roles as well as user-defined roles.db.getRoles()
wraps therolesInfo
command.
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.
Example
The following operations return documents for all the roles on the
products
database, including role privileges and built-in roles:
db.getRoles( { rolesInfo: 1, showPrivileges:true, showBuiltinRoles: true } )