diff --git a/source/includes/apiargs-dbcommand-shardCollection-field.yaml b/source/includes/apiargs-dbcommand-shardCollection-field.yaml index b5da2a28248..496615a27ea 100644 --- a/source/includes/apiargs-dbcommand-shardCollection-field.yaml +++ b/source/includes/apiargs-dbcommand-shardCollection-field.yaml @@ -11,8 +11,20 @@ type: string --- arg_name: field description: | - The index specification document to use as the shard key. The shard - key determines how MongoDB distributes the documents among the shards. + The index specification document to use as the + :doc:`shard key `. The shard key + determines how MongoDB distributes the documents among the shards. + + The *key* of the index specification document is the field to use as + the shard key. The *value* of the document must be one of the + following: + + - ``1`` to indicate forward traversal for the field. + + - ``-1`` to indicate reverse traversal for the field. + + - ``"hashed"`` to specify a + :ref:`hashed shard key `. Unless the collection is empty, the index must exist prior to the :dbcommand:`shardCollection` command. If the collection is empty, @@ -48,7 +60,7 @@ description: | shard key `. MongoDB will then create and balance chunks across the cluster. The ``numInitialChunks`` must be less than ``8192`` per shard. - + .. versionchanged:: 3.4 If the collection is not empty or the shard key is not a hashed diff --git a/source/reference/command/shardCollection.txt b/source/reference/command/shardCollection.txt index 129205b2bc9..1fcba0ff4d9 100644 --- a/source/reference/command/shardCollection.txt +++ b/source/reference/command/shardCollection.txt @@ -61,11 +61,14 @@ Choosing the best shard key to effectively distribute load among your shards requires some planning. Review :ref:`sharding-shard-key` regarding choosing a shard key and restrictions. +.. _hashed-shard-keys: + Hashed Shard Keys ~~~~~~~~~~~~~~~~~ :ref:`Hashed shard keys ` use a -hashed index of a single field as the shard key. +:doc:`hashed index ` of a +single field as the shard key. Use the form ``{field: "hashed"}`` to specify a hashed shard key. Hashed shard keys may not be compound indexes.