-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathsh.enableSharding.txt
124 lines (79 loc) · 2.8 KB
/
sh.enableSharding.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
===================
sh.enableSharding()
===================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. method:: sh.enableSharding(database, primaryShard)
.. note::
.. versionchanged:: 6.0
Starting in MongoDB 6.0, this method is **not** required to
:ref:`shard <sharding-background>` a collection.
Explicitly creates a database. Use the :binary:`~bin.mongosh` method
:method:`sh.shardCollection()` to shard collections on the database.
The :binary:`~bin.mongosh` method :method:`sh.enableSharding()` wraps the
:dbcommand:`enableSharding` command.
.. |dbcommand| replace:: :dbcommand:`enableSharding` command
.. include:: /includes/fact-mongosh-shell-method-alt.rst
Compatibility
-------------
This method is available in deployments hosted in the following environments:
.. include:: /includes/fact-environments-atlas-only.rst
.. include:: /includes/fact-environments-atlas-support-no-free.rst
.. include:: /includes/fact-environments-onprem-only.rst
Syntax
------
The :method:`sh.enableSharding` has the following form:
.. code-block:: javascript
sh.enableSharding(
<database>,
<primary shard> // Optional.
)
Parameter
~~~~~~~~~
The :method:`sh.enableSharding()` method takes the following parameter:
.. list-table::
:header-rows: 1
:widths: 20 20 60
* - Parameter
- Type
- Description
* - :ref:`database <method-enableSharding-db>`
- String
- .. _method-enableSharding-db:
The name of the database you want to create.
* - :ref:`primaryShard <method-enableSharding-primaryShard>`
- String
- .. _method-enableSharding-primaryShard:
.. include:: /includes/primary-shard-enable-sharding-opt.rst
Behavior
--------
Write Concern
~~~~~~~~~~~~~~
.. include:: /includes/extracts/mongos-operations-wc-enable-sharding.rst
Primary Shard
~~~~~~~~~~~~~
In general, you should not need to specify the :ref:`primaryShard
<method-enableSharding-primaryShard>` in the command. Instead, allow the
balancer to select the primary shard.
However, if you do specify the :ref:`primary shard
<method-enableSharding-primaryShard>` for a database and the database
is already enabled for sharding with a different primary shard, the
operation returns an error and the primary shard for the database
remains as before. To change the primary shard for a database, use the
:dbcommand:`movePrimary` command instead.
Example
-------
The following example, run from a :binary:`~bin.mongos`, explicitly
creates the ``shardTest`` database:
.. code-block:: javascript
sh.enableSharding("shardTest")
To verify, run :method:`sh.status()`.
.. seealso::
- :method:`sh.shardCollection()`
- :doc:`/tutorial/deploy-shard-cluster`