/
configureCollectionBalancing.txt
126 lines (90 loc) · 2.91 KB
/
configureCollectionBalancing.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
125
================================
configureCollectionBalancing
================================
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
.. meta::
:description: configureCollectionBalancing
:keywords: configureCollectionBalancing
Definition
------------
.. dbcommand:: configureCollectionBalancing
.. versionadded:: 5.3
Configures balancer settings for a sharded collection, such as
setting the chunk size for and defragmenting the collection.
Syntax
------
The command has the following syntax:
.. code-block:: javascript
db.adminCommand(
{
configureCollectionBalancing: "<collection>",
chunkSize: <num>,
defragmentCollection: <bool>
}
)
Command Fields
~~~~~~~~~~~~~~
:dbcommand:`configureCollectionBalancing` has the following fields:
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Field
- Type
- Description
* - ``configureCollectionBalancing``
- string
- Required: The name of the database and sharded collection to
configure.
* - ``chunkSize``
- integer
- Optional: Sets the chunk size in MiB for the collection. The
recommended size is 256, 512, or larger.
* - ``defragmentCollection``
- boolean
- Optional: Causes the balancer to defragment the collection.
For more information, see :ref:`Data Partitioning with Chunks
<sharding-data-partitioning>`.
Examples
----------
Configure Chunk Size
~~~~~~~~~~~~~~~~~~~~~~
To change the chunk size for a sharded collection, use
the ``chunkSize`` option:
.. code-block:: javascript
db.adminCommand( {
configureCollectionBalancing: "test.students",
chunkSize: 256
} )
Use this command to change the chunk size for the given collection.
.. warning::
By default, MongoDB cannot move a chunk if the number of documents in
the chunk is greater than 1.3 times the result of dividing the
configured chunk size by the average document size.
To find the average document size, see the ``avgObjSize`` field in the
output of the :method:`db.collection.stats()` method.
For more information, see :ref:`Chunk Size <sharding-chunk-size>`.
Defragment Collections
~~~~~~~~~~~~~~~~~~~~~~~~
To tell the balancer to defragment a sharded collection, use the
``defragmentCollection`` option:
.. code-block:: javascript
db.adminCommand( {
configureCollectionBalancing: "test.students",
defragmentCollection: true
} )
Use this command to have the balancer defragment a sharded collection.
Reconfigure and Defragment Collections
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To defragment a sharded collection while updating the chunk size, use
the ``defragmentCollection`` option and the ``chunkSize`` option
together:
.. code-block:: javascript
db.adminCommand( {
configureCollectionBalancing: "test.students",
chunkSize: 512,
defragmentCollection: true
} )