Skip to content

DOCS-9365: Shell helper sh.shardCollection() takes options parameter #2806

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 3 commits 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
5 changes: 3 additions & 2 deletions source/includes/apiargs-dbcommand-shardCollection-field.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ arg_name: field
description: |
When ``true``, the ``unique`` option ensures that the underlying index
enforces a unique constraint. Hashed shard keys do not support unique
constraints.
constraints. Defaults to ``false``.

interface: dbcommand
name: unique
Expand Down Expand Up @@ -60,7 +60,8 @@ arg_name: field
description: |
If the collection specified to ``shardCollection``
has a default :doc:`collation </reference/collation>`,
you *must* set {{role}} to ``{ locale : "simple"}``, or
you *must* include a collation document with
``{ locale : "simple" }``, or
the ``shardCollection`` command fails. At least one of the indexes
whose fields support the shard key pattern must have the simple
collation.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
arg_name: param
source:
file: apiargs-dbcommand-shardCollection-field.yaml
ref: numInitialChunks

interface: method
name: numInitialChunks
operation: sh.shardCollection
optional: true
position: 1
type: integer
---
arg_name: param
source:
file: apiargs-dbcommand-shardCollection-field.yaml
ref: collation
interface: method
name: collation
operation: sh.shardCollection
optional: true
position: 2
type: document
...
13 changes: 12 additions & 1 deletion source/includes/apiargs-method-sh.shardCollection-param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ source:
interface: method
name: unique
operation: sh.shardCollection
optional: false
optional: true
position: 3
type: boolean
---
arg_name: param
description: |
A document containing optional fields, including
``numInitialChunks`` and ``collation``.
interface: method
name: options
operation: sh.shardCollection
optional: true
position: 4
type: document
...
4 changes: 4 additions & 0 deletions source/includes/extracts-collation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ content: |-
| :method:`db.collection.updateMany()`,
| :method:`db.collection.replaceOne()`

* - :dbcommand:`shardCollection`

- | :method:`sh.shardCollection()`

* -

- Individual update, replace, and delete operations in
Expand Down
14 changes: 14 additions & 0 deletions source/includes/fact-shardCollection-collation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Collation
~~~~~~~~~

.. versionchanged:: 3.4

If the collection has a default :doc:`collation</reference/collation>`,
the |command| command must include a ``collation`` parameter with the
value ``{ locale: "simple" }``. For non-empty collections with a
default collation, you must have at least one index with the simple
collation whose fields support the shard key pattern.

You do not need to specify the ``collation`` option for collections
without a collation. If you do specify the collation option for
a collection with no collation, it will have no effect.
16 changes: 1 addition & 15 deletions source/reference/command/shardCollection.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,7 @@ If specifying ``unique: true``:
See also :ref:`Sharded Collection and Unique Indexes
<sharding-shard-key-unique>`

Collation
~~~~~~~~~

.. versionchanged:: 3.4

If the collection has a default :doc:`collation</reference/collation>`,
your :dbcommand:`shardCollection` command must include a
``collation`` parameter with the value ``{ locale: "simple" }``.
For non-empty collections with a collation, you must have at
least one index with the simple collation whose fields support the
shard key pattern.

You do not need to specify the ``collation`` option for collections
without a collation. If you do specify the collation option for
a collection with no collation, it will have no effect.
.. include:: /includes/fact-shardCollection-collation.rst

Example
-------
Expand Down
42 changes: 35 additions & 7 deletions source/reference/method/sh.shardCollection.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ sh.shardCollection()
Definition
----------

.. method:: sh.shardCollection(namespace, key, unique)
.. method:: sh.shardCollection(namespace, key, unique, options)

.. |command| replace:: :method:`sh.shardCollection`

Shards a collection using the ``key`` as a the :term:`shard
key`. :method:`sh.shardCollection()` takes the following arguments:

.. include:: /includes/apiargs/method-sh.shardCollection-param.rst

The ``options`` argument supports the following options:

.. include:: /includes/apiargs/method-sh.shardCollection-options-param.rst

Considerations
--------------

Expand Down Expand Up @@ -54,16 +60,38 @@ If specifying ``unique: true``:

See also :ref:`Sharded Collection and Unique Indexes
<sharding-shard-key-unique>`

.. include:: /includes/fact-shardCollection-collation.rst

Example
-------
Examples
--------

Simple Usage
~~~~~~~~~~~~

Given the ``people`` collection in the ``records`` database, the
following command shards the collection by the ``zipcode`` field:
Given a collection named ``people`` in a database named ``records``,
the following command shards the collection by the
``zipcode`` field:

.. code-block:: javascript

sh.shardCollection("records.people", { zipcode: 1} )
sh.shardCollection("records.people", { zipcode: 1 } )

.. seealso:: :dbcommand:`shardCollection`, :doc:`/sharding`
Usage with Options
~~~~~~~~~~~~~~~~~~

Given a collection named ``contacts`` in a database named ``phonebook``,
the following command:

- Shards the collection by the ``last_name`` field.
- Indicates that there is no unique constraint on the underlying
index.
- Specifies ``5`` initial chunks.
- Specifies a :doc:`collation</reference/collation>`.

.. code-block:: javascript

sh.shardCollection("phonebook.contacts", { last_name: 1 }, false,
{ numInitialChunks: 5, collation: { locale: "simple" } } )

.. seealso:: :dbcommand:`shardCollection`, :doc:`/sharding`