Skip to content

DOCS-1492 db.addUser, db.cloneCollection, db.copyDatabase #1051

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
35 changes: 35 additions & 0 deletions source/reference/method/db.addUser-param-2.2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
object:
name: db.addUser()
type: method
field:
optional: false
type: param
name: user
type: string
position: 1
description: "The username."
---
object:
name: db.addUser()
type: method
field:
optional: false
type: param
name: password
type: string
position: 2
description: "The corresponding password."
---
object:
name: db.addUser()
type: method
field:
optional: true
type: param
name: readOnly
type: boolean
position: 3
description: |
Defaults to ``false``. Grants users a restricted privilege set that
only allows the user to read the this database.
...
65 changes: 48 additions & 17 deletions source/reference/method/db.addUser-param.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,64 @@
object:
name:
type:
name: db.addUser()
type: method
field:
optional: false
type: param
name:
type:
name: user
type: string
position: 1
description: ""
description: |
The name of the user who is given access to the database.
---
object:
name:
type:
name: db.addUser()
type: method
field:
optional:
optional: true
type: param
name:
type:
name: pwd
type: hash
position: 2
description: ""
description: |
A shared secret used to authenticate the user. The ``pwd`` field and
the ``userSource`` field are mutually exclusive. The document cannot
contain both.
---
object:
name:
type:
name: db.addUser()
type: method
field:
optional:
optional: true
type: param
name:
type:
name: roles
type: array
position: 3
description: ""
description: |
An array of user roles.
---
object:
name: db.addUser()
type: method
field:
optional: true
type: param
name: userSource
type: string
position: 4
description: |
The database that contains the credentials for the user. The
``userSource`` field and the ``pwd`` field are mutually exclusive.
The document cannot contain both.
---
object:
name: db.addUser()
type: method
field:
optional: true
type: param
name: otherDBRoles
type: document
position: 5
description: |
Roles this user has on other databases.
...
115 changes: 58 additions & 57 deletions source/reference/method/db.addUser.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ db.addUser()

.. default-domain:: mongodb

Definition
----------

.. method:: db.addUser()

Use :method:`db.addUser()` to add privilege documents to the
Expand All @@ -23,92 +26,90 @@ db.addUser()
to :method:`db.addUser()` that describe :ref:`user credentials
<v2.2-style-addUser>`.

See :doc:`/reference/privilege-documents` for more information
about the form of the 2.4 privilege documents.

Consider the following prototypes form for a :method:`db.addUser()`
operations:
The method contains a 2.4 privilege document with a subset of the
following fields. For detailed information about the form of the 2.4
privilege documents, see :doc:`/reference/privilege-documents`.

.. code-block:: javascript
.. include:: /reference/method/db.addUser-param.rst

db.addUser( { user: "<user>", pwd: "<password>", roles: [<roles>] } )
Examples
--------

This operation creates a :data:`system.users
<<database>.system.users>` document with a password using the
:data:`~<database>.system.users.pwd` field
The following are prototype :method:`db.addUser()` operations:

In the following prototype, rather than specify a password
directly, you can delegated the credential to another database
using the :data:`~<database>.system.users.userSource` field:
.. code-block:: javascript

.. code-block:: javascript
db.addUser( { user: "<user>", pwd: "<password>", roles: [<roles>] } )

db.addUser( { user: "<user>", userSource: "<database>", roles: [<roles>] } )
This operation creates a :data:`system.users
<<database>.system.users>` document with a password using the
:data:`~<database>.system.users.pwd` field

.. example::
In the following prototype, rather than specify a password
directly, you can delegated the credential to another database
using the :data:`~<database>.system.users.userSource` field:

To create and add a 2.4-style privilege document to
:data:`system.users <<database>.system.users>` to grant
:authrole:`readWrite` privileges to a user named "author" with
privileges, use the following operation:
.. code-block:: javascript

.. code-block:: javascript
db.addUser( { user: "<user>", userSource: "<database>", roles: [<roles>] } )

db.addUser( { user: "author", pwd: "pass", roles: [ "readWrite" ] } )
To create and add a 2.4-style privilege document to
:data:`system.users <<database>.system.users>` to grant
:authrole:`readWrite` privileges to a user named "author" with
privileges, use the following operation:

If you want to store user credentials in a single ``users``
database, you can use :ref:`delegated credentials
<delegated-credentials>`, as in the following example:
.. code-block:: javascript

.. code-block:: javascript
db.addUser( { user: "author", pwd: "pass", roles: [ "readWrite" ] } )

db.addUser( { user: "author", userSource: "users", roles: [ "readWrite" ] } )
If you want to store user credentials in a single ``users``
database, you can use :ref:`delegated credentials
<delegated-credentials>`, as in the following example:

.. seealso::
.. code-block:: javascript

- :doc:`/tutorial/add-user-to-database`
db.addUser( { user: "author", userSource: "users", roles: [ "readWrite" ] } )

- :doc:`/reference/user-privileges`
.. seealso::

- :doc:`/reference/privilege-documents`
- :doc:`/tutorial/add-user-to-database`

.. _v2.2-style-addUser:
- :doc:`/reference/user-privileges`

To create legacy (2.2. and earlier) privilege documents,
:method:`db.addUser()` provides accepts the following parameters:
- :doc:`/reference/privilege-documents`

:param string user: Specifies the username.
Legacy Privilege Documents
--------------------------

:param string password: Specifies the corresponding password.
.. _v2.2-style-addUser:

:param boolean readOnly:
To create legacy (2.2. and earlier) privilege documents,
:method:`db.addUser()` accepts the following parameters.

Optional. Defaults to ``false``. Grants users a restricted
privilege set that only allows the user to read the this
database.
.. include:: /reference/method/db.addUser-param-2.2.rst

Consider the following syntax:
The command takes the following form:

.. code-block:: javascript
.. code-block:: javascript

db.addUser( "<username>", "<password>", { readOnly: <boolean> } )
db.addUser( "<username>", "<password>", { readOnly: <boolean> } )

.. example::
.. example::

To create and add a legacy (2.2. and earlier) privilege
document with a user named ``guest`` and the password ``pass``
that has only ``readOnly`` privileges, use the following
operation:
To create and add a legacy (2.2. and earlier) privilege document with
a user named ``guest`` and the password ``pass`` that has only
``readOnly`` privileges, use the following operation:

.. code-block:: javascript
.. code-block:: javascript

db.addUser( "guest", "pass", { readOnly: true } )
db.addUser( "guest", "pass", { readOnly: true } )

.. note:: The :program:`mongo` shell excludes all
:method:`db.addUser()` operations from the saved history.
.. note:: The :program:`mongo` shell excludes all
:method:`db.addUser()` operations from the saved history.

.. deprecated:: 2.4 The ``roles`` parameter replaces the
``readOnly`` parameter for :method:`db.addUser()`. 2.4 also adds
the :data:`~admin.system.users.otherDBRoles` and
:data:`~<database>.system.users.userSource` fields to documents in the
:data:`system.users <<database>.system.users>` collection.
.. deprecated:: 2.4 The ``roles`` parameter replaces the ``readOnly``
parameter for :method:`db.addUser()`. 2.4 also adds the
:data:`~admin.system.users.otherDBRoles` and
:data:`~<database>.system.users.userSource` fields to
documents in the :data:`system.users
<<database>.system.users>` collection.
44 changes: 27 additions & 17 deletions source/reference/method/db.cloneCollection-param.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
object:
name:
type:
name: db.cloneCollection()
type: method
field:
optional: false
type: param
name:
type:
name: from
type: string
position: 1
description: ""
description: |
Host name of the MongoDB instance that holds the collection to copy.
---
object:
name:
type:
name: db.cloneCollection()
type: method
field:
optional:
optional: false
type: param
name:
type:
name: collection
type: string
position: 2
description: ""
description: |
The collection in the MongoDB instance that you want to copy.
:method:`db.cloneCollection()` will only copy the collection with this
name from *database* of the same name as the current database the
remote MongoDB instance. If you want to copy a collection from a
different database name you must use the :dbcommand:`cloneCollection`
directly.
---
object:
name:
type:
name: db.cloneCollection()
type: method
field:
optional:
optional: true
type: param
name:
type:
name: query
type: document
position: 3
description: ""
description: |
A standard :ref:`MongoDB query document <mongodb-query-document>` to
limit the documents copied as part of the
:method:`db.cloneCollection()` operation.
...
35 changes: 14 additions & 21 deletions source/reference/method/db.cloneCollection.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,22 @@ db.cloneCollection()

.. default-domain:: mongodb

Definition
----------

.. method:: db.cloneCollection(from, collection, query)

:method:`db.cloneCollection()` provides a wrapper around
:dbcommand:`cloneCollection` for copying data directly between
Copies data directly between
MongoDB instances. :method:`db.cloneCollection()` does not allow
you to clone a collection through a :program:`mongos`: you must
you to clone a collection through a :program:`mongos`. You must
connect directly to the :program:`mongod` instance.

:param string from: A host name, of the MongoDB instance that holds
the collection you wish to copy

:param string collection: A collection in the MongoDB instance that
you want to
copy. :method:`db.cloneCollection()` will
only copy the collection with this name
from *database* of the same name as the
current database the remote MongoDB
instance. If you want to copy a
collection from a different database name
you must use the
:dbcommand:`cloneCollection` directly.

:param document query: Optional. A standard :ref:`MongoDB query
document <mongodb-query-document>` to limit
the documents copied as part of the
:method:`db.cloneCollection()` operation.
The method contains the following fields:

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

The :method:`db.cloneCollection()` method provides a wrapper around
:dbcommand:`cloneCollection`.

.. Example
.. -------
Loading