Skip to content

assign a user a role #1408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions source/tutorial/assign-a-user-a-role.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
====================
Assign a User a Role
====================

.. default-domain:: mongodb

Overview
--------

Assign a user a role to give the user access to resources according to the
operational needs of the deployment.

Prerequisites
-------------

.. include:: /includes/access-grant-user-role.rst

Procedure
---------

Identify the Privileges to Assign
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Identify the :doc:`privileges </reference/user-privileges>` to make
available to the user. Privileges are combinations of database resources
and :ref:`actions <security-user-actions>`.

Identify the Role with Those Privileges
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Determine whether an existing role contains those privileges, and only
those privileges. If such a role does not exist, see the :docs:`procedure
for creating a role </tutorial/define-roles>`.

Grant the Role to the User
~~~~~~~~~~~~~~~~~~~~~~~~~~

Grant the role using the :dbcommand:`grantRolesToUser` command. For
example, to grant the user ``Alice`` the :authrole:`read` role on the
``stock`` database, run the following.

.. code-block:: javascript

db.runCommand( { grantRolesToUser: "Alice",
roles: [
{ role: "read", db: "stock"},
],
} )

The :dbcommand:`grantRolesToUser` command adds role to ``Alice``'s
existing roles.