Skip to content

DOCS-2245 add the grantRolesToUser method #1415

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
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions bin/builddata/htaccess.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3275,4 +3275,12 @@ code: 301
outputs:
- 'master'
- 'manual'
---
redirect-path: '/reference/method/db.grantRolesToUser'
url-base: '/reference/security'
type: 'redirect'
code: 301
outputs:
- 'manual'
- 'before-v2.4'
...
10 changes: 5 additions & 5 deletions source/includes/ref-toc-method-user-management.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ description: |
# description: |
# Deletes all users associated with a database.
# ---
# name: :method:`db.grantRolesToUser()`
# file: /reference/method/db.grantRolesToUser
# description: |
# Grants a role and its privileges to a user.
# ---
name: :method:`db.grantRolesToUser()`
file: /reference/method/db.grantRolesToUser
description: |
Grants a role and its privileges to a user.
---
# name: :method:`db.revokeRolesFromUser()`
# file: /reference/method/db.revokeRolesFromUser
# description: |
Expand Down
14 changes: 6 additions & 8 deletions source/reference/command/grantRolesToUser.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Definition

.. dbcommand:: grantRolesToUser

Grants an additional role to a user. Use :dbcommand:`grantRolesToUser` to grant
one or more roles.
Grants additional roles to a user.

The :dbcommand:`grantRolesToUser` command uses the following syntax:

Expand All @@ -36,7 +35,7 @@ Required Access
Example
-------

Given a user ``Erin`` in the ``products`` database with the following
Given a user ``accountUser01`` in the ``products`` database with the following
roles:

.. code-block:: javascript
Expand All @@ -47,23 +46,22 @@ roles:
}
]

The following :dbcommand:`grantRolesToUser` command gives ``Erin`` the
The following :dbcommand:`grantRolesToUser` operation gives ``accountUser01`` the
:authrole:`read` role on the ``stock`` database and the
:authrole:`readWrite` role on the ``products`` database where the
:dbcommand:`grantRolesToUser` command runs.
:authrole:`readWrite` role on the ``products`` database.

.. code-block:: javascript

use products
db.runCommand( { grantRolesToUser: "Erin",
db.runCommand( { grantRolesToUser: "accountUser01",
roles: [
{ role: "read", db: "stock"},
"readWrite"
],
writeConcern: { w: "majority" , wtimeout: 2000 }
} )

The user ``Erin`` in the ``products`` database now has the following
The user ``accountUser01`` in the ``products`` database now has the following
roles:

.. code-block:: javascript
Expand Down
20 changes: 20 additions & 0 deletions source/reference/method/db.grantRolesToUser-param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
object:
name: db.grantRolesToUser
type: method
field:
optional: false
type: param
name: user
type: string
position: 1
description: |
The name of the user to whom to grant roles.
---
file: /reference/command/grantRolesToUser-field.yaml
name: roles
position: 2
---
file: /reference/command/grantRolesToUser-field.yaml
name: writeConcern
position: 3
...
77 changes: 77 additions & 0 deletions source/reference/method/db.grantRolesToUser.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
=====================
db.grantRolesToUser()
=====================

.. default-domain:: mongodb

Definition
----------

.. method:: db.grantRolesToUser ( username, roles, writeConcern )

Grants additional roles to a user.

The :method:`grantRolesToUser` method uses the following syntax:

.. code-block:: javascript

db.grantRolesToUser( "<username>", [<roles>], {writeConcern} )

The :method:`grantRolesToUser` method takes the following arguments:

.. include:: /reference/method/db.grantRolesToUser-param.rst

.. |local-cmd-name| replace:: :method:`db.grantRolesToUser()`
.. include:: /includes/fact-roles-array-contents.rst

The :method:`db.grantRolesToUser()` method wraps the
:dbcommand:`grantRolesToUser` command.

Required Access
---------------

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

Example
-------


Given a user ``accountUser01`` in the ``products`` database with the following
roles:

.. code-block:: javascript

"roles" : [
{ "role" : "assetsReader",
"db" : "assets"
}
]

The following :method:`grantRolesToUser()` operation gives ``accountUser01``
the :authrole:`readWrite` role on the ``products`` database and the
:authrole:`read` role on the ``stock`` database.

.. code-block:: javascript

use products
db.grantRolesToUser( "accountUser01",
[ "readWrite" , { role: "read", db: "stock"} ],
{ w: "majority" , wtimeout: 4000 }
} )

The user ``accountUser01`` in the ``products`` database now has the following
roles:

.. code-block:: javascript

"roles" : [
{ "role" : "assetsReader",
"db" : "assets"
},
{ "role" : "read",
"db" : "stock"
},
{ "role" : "readWrite",
"db" : "products"
}
]