Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
295 lines (200 sloc) 7.53 KB
=========
rolesInfo
=========
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. dbcommand:: rolesInfo
Returns inheritance and privilege information for specified roles,
including both :ref:`user-defined roles <user-defined-roles>` and
:ref:`built-in roles <built-in-roles>`.
The :dbcommand:`rolesInfo` command can also retrieve all roles
scoped to a database.
To match a single role on the database, use the following form:
.. code-block:: javascript
{
rolesInfo: { role: <name>, db: <db> },
showPrivileges: <Boolean>,
showBuiltinRoles: <Boolean>
}
:dbcommand:`rolesInfo` has the following fields:
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Field
- Type
- Description
* - ``rolesInfo``
- string, document, array, or integer
- The role(s) to return information about. For the syntax for specifying
roles, see :ref:`rolesinfo-behavior`.
* - ``showPrivileges``
- boolean
- Optional. Set the field to ``true`` 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``
- boolean
- Optional. When the ``rolesInfo`` field is set to ``1``, set ``showBuiltinRoles`` to
``true`` to include :ref:`built-in roles <built-in-roles>` in the output.
By default this field is set to ``false``, and the output for ``rolesInfo:
1`` displays only :ref:`user-defined roles <user-defined-roles>`.
.. _rolesinfo-behavior:
Behavior
--------
Return Information for a Single Role
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To specify a role from the current database, specify the role by its name:
.. code-block:: javascript
{ rolesInfo: "<rolename>" }
To specify a role from another database, specify the role by a document that
specifies the role and database:
.. code-block:: javascript
{ rolesInfo: { role: "<rolename>", db: "<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:
.. code-block:: javascript
{
rolesInfo: [
"<rolename>",
{ role: "<rolename>", db: "<database>" },
...
]
}
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 :ref:`user-defined roles
<user-defined-roles>` in the database. To include :ref:`built-in roles
<built-in-roles>` as well, include the parameter-value pair
``showBuiltinRoles: true``:
.. code-block:: javascript
{ rolesInfo: 1, showBuiltinRoles: true }
Required Access
---------------
.. include:: /includes/access-roles-info.rst
.. _rolesinfo-output:
Output
------
.. data:: rolesInfo.role
The name of the role.
.. data:: rolesInfo.db
The database on which the role is defined. Every database has :ref:`built-in
roles <built-in-roles>`. A database might also have :ref:`user-defined
roles <user-defined-roles>`.
.. data:: rolesInfo.isBuiltin
A value of ``true`` indicates the role is a :ref:`built-in role
<built-in-roles>`. A value of ``false`` indicates the role is a
:ref:`user-defined role <user-defined-roles>`.
.. data:: rolesInfo.roles
The roles that directly provide privileges to this role and the databases
on which the roles are defined.
.. data:: rolesInfo.inheritedRoles
All roles from which this role inherits privileges. This includes the roles
in the :data:`rolesInfo.roles` array as well as the roles from which the
roles in the :data:`rolesInfo.roles` array 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.
.. data:: 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 :data:`~rolesInfo.privileges` field. To
include the field, specify ``showPrivileges: true`` when running the
:dbcommand:`rolesInfo` command.
Each privilege document specifies the :ref:`resources
<resource-document>` and the :doc:`actions
</reference/privilege-actions>` allowed on the resources.
.. data:: rolesInfo.inheritedPrivileges
All privileges granted by this role, including those inherited from
other roles. By default the output does not include the
:data:`~rolesInfo.inheritedPrivileges` field. To include the field,
specify ``showPrivileges: true`` when running the
:dbcommand:`rolesInfo` command.
Each privilege document specifies the :ref:`resources
<resource-document>` and the :doc:`actions
</reference/privilege-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:
.. code-block:: javascript
db.runCommand(
{
rolesInfo: { role: "associate", db: "products" }
}
)
The following command returns the role inheritance information for the role
``siteManager`` on the database on which the command runs:
.. code-block:: javascript
db.runCommand(
{
rolesInfo: "siteManager"
}
)
The following command returns *both* the role inheritance and the privileges
for the role ``associate`` defined on the ``products`` database:
.. code-block:: javascript
db.runCommand(
{
rolesInfo: { role: "associate", db: "products" },
showPrivileges: true
}
)
View Information for Several Roles
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following command returns information for two roles on two different
databases:
.. code-block:: javascript
db.runCommand(
{
rolesInfo: [
{ role: "associate", db: "products" },
{ role: "manager", db: "resources" }
]
}
)
The following returns *both* the role inheritance and the privileges:
.. code-block:: javascript
db.runCommand(
{
rolesInfo: [
{ role: "associate", db: "products" },
{ role: "manager", db: "resources" }
],
showPrivileges: true
}
)
View All User-Defined Roles for a Database
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following operation returns all :ref:`user-defined roles
<user-defined-roles>` on the database on which the command runs and includes
privileges:
.. code-block:: javascript
db.runCommand(
{
rolesInfo: 1,
showPrivileges: true
}
)
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:
.. code-block:: javascript
db.runCommand(
{
rolesInfo: 1,
showBuiltinRoles: true
}
)
You can’t perform that action at this time.