-
Notifications
You must be signed in to change notification settings - Fork 1.7k
DOCS-1153 adduser #772
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
Closed
DOCS-1153 adduser #772
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,25 +4,109 @@ db.addUser() | |
|
||
.. default-domain:: mongodb | ||
|
||
.. method:: db.addUser("username", "password" [, readOnly] ) | ||
.. method:: db.addUser() | ||
|
||
:param string username: Specifies a new username. | ||
Use this method to create new database users by specifying a | ||
username, password, and privileges. | ||
|
||
:param string password: Specifies the corresponding password. | ||
In MongoDB 2.4 you must pass :method:`db.addUser()` a document that | ||
contains the user parameters. You cannot pass the parameters | ||
directly. In MongoDB 2.2 and earlier you can pass the parameters | ||
directly, or pass a document. | ||
|
||
If you use MongoDB 2.4, the following parameters define users: | ||
|
||
:param string user: Specifies a new username. | ||
|
||
:param string pwd: Specifies the corresponding password. | ||
Specify either this parameter or the | ||
``userSource`` parameter. The two fields are | ||
mutually exclusive. A single document cannot | ||
contain both. | ||
|
||
:param array roles: This specifies one or more | ||
roles to the user. Each role provides the user | ||
with a set of privileges. For a list of roles, | ||
see :data:`system.users.roles <<database>.system.users.roles>`. | ||
|
||
:param boolean readOnly: Optional. Restrict a user to | ||
read-privileges only. Defaults to false. | ||
:param string userSource: This specifies | ||
the database that contains the user | ||
credentials. Specify either this parameter | ||
or the ``pwd`` parameter. The two fields | ||
are mutually exclusive. A single document | ||
cannot contain both. | ||
|
||
Use this function to create new database users, by specifying a | ||
username and password as arguments to the command. If you want to | ||
restrict the user to have only read-only privileges, supply a true | ||
third argument; however, this defaults to false. | ||
:param document otherDBRoles: Optional. This | ||
specifies the roles that an admin user | ||
has on other databases. This field | ||
applies only to a user added to the | ||
``admin`` database. For a list of | ||
roles, see :data:`system.users.roles | ||
<<database>.system.users.roles>`. | ||
|
||
For example: | ||
For MongoDB 2.4, use the syntax described here. | ||
|
||
To specify the password: | ||
|
||
.. code-block:: javascript | ||
|
||
db.addUser("user1" , "pass" , { readOnly : true } ) | ||
db.addUser( { user: "<user>", pwd: "<password>", roles: [<roles>] } ) | ||
|
||
To specify the database that contains the user credentials: | ||
|
||
.. code-block:: javascript | ||
|
||
db.addUser( { user: "<user>", userSource: "<database>", roles: [<roles>] } ) | ||
|
||
To give an admin user roles on other databases, include the following | ||
field in the document passed to the :method:`db.addUser()` method: | ||
|
||
.. code-block:: javascript | ||
|
||
otherDBRoles: { <database1>: [<roles>], <database2>: [<roles>] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is only permissible on the admin database which is not necessarily the same as an admin user. |
||
|
||
.. example:: On MongoDB 2.4, the following creates a user named | ||
"author" with ``readWrite`` and ``readAnyDatabase`` privileges: | ||
|
||
.. code-block:: javascript | ||
|
||
db.addUser( { user: "author", pwd: "pass", roles: [ "readWrite", "readAnyDatabase" ] } ) | ||
|
||
.. seealso:: | ||
|
||
- :doc:`/reference/user-privileges` | ||
|
||
- :doc:`/reference/privilege-documents` | ||
|
||
If you use MongoDB 2.2 or earlier, the following parameters define | ||
users: | ||
|
||
:param string user: Specifies a new username. | ||
|
||
:param string password: Specifies the corresponding password. | ||
|
||
:param boolean readOnly: Optional. If you use MongoDB 2.2 or earlier, | ||
this restricts a user to | ||
read privileges. This defaults to false. | ||
|
||
Use the following syntax. The | ||
``readOnly`` field is optional and defaults to ``false``: | ||
|
||
.. code-block:: javascript | ||
|
||
db.addUser( "<username>", "<password>", { readOnly: <boolean> } ) | ||
|
||
.. example:: On MongoDB 2.2 and earlier, the following creates a user | ||
named "guest" with ``readOnly`` privileges: | ||
|
||
.. code-block:: javascript | ||
|
||
db.addUser( "guest", "pass", { readOnly: true } ) | ||
|
||
.. note:: The :program:`mongo` shell excludes all | ||
:method:`db.addUser()` operations from the saved history. | ||
|
||
.. |operation-name| replace:: :method:`db.addUser()` | ||
.. include:: /includes/note-auth-methods-excluded-from-shell-history.rst | ||
.. deprecated:: 2.4 | ||
The ``roles`` parameter replaces the ``readOnly`` parameter for | ||
:method:`db.addUser()`. Version 2.4 also adds the ``otherDBRoles`` | ||
and ``userSource`` parameters to :method:`db.addUser()`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct but redundant to document fields that are documented in the system.users documentation.