@@ -18,8 +18,8 @@ Definition
1818.. dbcommand:: compact
1919
2020 Rewrites and defragments all data and indexes in a collection. On
21- :ref:`WiredTiger <storage-wiredtiger>` databases, this command will release
22- unneeded disk space to the operating system.
21+ :ref:`WiredTiger <storage-wiredtiger>` databases, this command
22+ releases unneeded disk space to the operating system.
2323
2424Syntax
2525------
@@ -39,13 +39,6 @@ Command Fields
3939
4040The command takes the following fields:
4141
42- .. note:: Starting in MongoDB 4.2
43-
44-
45- MongoDB removes the MMAPv1 storage engine and the MMAPv1 specific
46- options ``paddingFactor``, ``paddingBytes``, ``preservePadding``
47- for :dbcommand:`compact`.
48-
4942
5043.. list-table::
5144 :header-rows: 1
@@ -65,16 +58,9 @@ The command takes the following fields:
6558
6659 .. _compact-force-option:
6760
68- Optional. Starting in v4.4, if specified, forces
69- :dbcommand:`compact` to run on the :term:`primary` in
70- a :term:`replica set`. Before v4.4, this boolean field
71- enabled :dbcommand:`compact` to run on the :term:`primary`
72- in a :term:`replica set` if the value was ``true`` and
73- returned an error when run on a :term:`primary` if the
74- value was ``false``, because the command blocked all other
75- operations.
76-
77- Starting in v4.4, :dbcommand:`compact` does not block
61+ Optional. If specified, forces
62+ ``compact`` to run on the :term:`primary` in
63+ a :term:`replica set`. ``compact`` does not block
7864 :ref:`crud` on the database it is compacting.
7965
8066 * - ``comment``
@@ -84,7 +70,7 @@ The command takes the following fields:
8470
8571
8672.. warning:: Always have an up-to-date backup before performing server
87- maintenance such as the :dbcommand:` compact` operation.
73+ maintenance such as the `` compact` ` operation.
8874
8975.. _compact-authentication:
9076
@@ -94,7 +80,7 @@ The command takes the following fields:
9480For clusters enforcing :ref:`authentication <authentication>`,
9581you must authenticate as a user with the :authaction:`compact` privilege
9682action on the target collection. The :authrole:`dbAdmin` role provides
97- the required privileges for running :dbcommand:` compact` against
83+ the required privileges for running `` compact` ` against
9884non-system collections.
9985
10086For more information on configuring the ``resource`` document, see
@@ -140,9 +126,6 @@ Blocking behavior is version specific.
140126 * - Version
141127 - Blocking Behavior
142128
143- * - Pre 4.4
144- - ``compact`` blocks all read and write activity.
145-
146129 * - 4.4
147130 - - .. include:: /includes/reference/compact-methods-list.rst
148131 - All other operations are permitted.
@@ -167,14 +150,14 @@ Operation Termination
167150
168151If you terminate the operation with the :method:`db.killOp()
169152<db.killOp()>` method or restart the server before the
170- :dbcommand:` compact` operation has finished, be aware of the following:
153+ `` compact` ` operation has finished, be aware of the following:
171154
172155- If you have journaling enabled, the data remains valid and
173- usable, regardless of the state of the :dbcommand:` compact` operation.
156+ usable, regardless of the state of the `` compact` ` operation.
174157 You may have to manually rebuild the indexes.
175158
176159- If you do not have journaling enabled and the :binary:`~bin.mongod` or
177- :dbcommand:` compact` terminates during the operation, it is impossible
160+ `` compact` ` terminates during the operation, it is impossible
178161 to guarantee that the data is in a valid state.
179162
180163- In either case, much of the existing free space in the collection may
@@ -187,14 +170,14 @@ Disk Space
187170To see how the storage space changes for the collection, run the
188171:dbcommand:`collStats` command before and after compaction.
189172
190- On :ref:`WiredTiger <storage-wiredtiger>`, :dbcommand:` compact` attempts
173+ On :ref:`WiredTiger <storage-wiredtiger>`, `` compact` ` attempts
191174to reduce the required storage space for data and indexes in a
192175collection, releasing unneeded disk space to the operating system. The
193176effectiveness of this operation is workload dependent and no disk space
194177may be recovered. This command is useful if you have removed a large
195178amount of data from the collection, and do not plan to replace it.
196179
197- :dbcommand:` compact` may require additional disk space to run on
180+ `` compact` ` may require additional disk space to run on
198181WiredTiger databases.
199182
200183.. _compact-cmd-replica-sets:
@@ -250,11 +233,6 @@ Blocking behavior on secondary nodes is version specific.
250233 * - Version
251234 - Blocking Behavior
252235
253- * - Pre 4.4
254- - - ``compact`` blocks all read and write activity.
255- - No replication possible.
256- - Secondary node is in :replstate:`RECOVERING` state.
257-
258236 * - 4.4
259237 - - ``compact`` blocks all write activity.
260238 - No replication possible.
@@ -277,20 +255,20 @@ For replica set maintenance and availability, see
277255Sharded Clusters
278256~~~~~~~~~~~~~~~~
279257
280- :dbcommand:` compact` only applies to :binary:`~bin.mongod` instances. In a
281- sharded environment, run :dbcommand:` compact` on each shard separately
258+ `` compact` ` only applies to :binary:`~bin.mongod` instances. In a
259+ sharded environment, run `` compact` ` on each shard separately
282260as a maintenance operation.
283261
284- You cannot issue :dbcommand:` compact` against a :binary:`~bin.mongos` instance.
262+ You cannot issue `` compact` ` against a :binary:`~bin.mongos` instance.
285263
286264Capped Collections
287265~~~~~~~~~~~~~~~~~~
288266
289- On :ref:`WiredTiger <storage-wiredtiger>`, the :dbcommand:` compact`
267+ On :ref:`WiredTiger <storage-wiredtiger>`, the `` compact` `
290268command will attempt to compact the collection.
291269
292270Index Building
293271~~~~~~~~~~~~~~
294272
295273:binary:`~bin.mongod` rebuilds all indexes in parallel following the
296- :dbcommand:` compact` operation.
274+ `` compact` ` operation.
0 commit comments