Compaction
You can leverage compaction to release unneeded disk space, taken up by data and collection indexes, to the operating system. To do this, run the compact
command on one of your deployment’s secondary nodes. The command has the following syntax:
db.runCommand({
compact: <string>,
dryRun: <boolean>,
force: <boolean>,
freeSpaceTargetMB: <int>,
comment: <any>
})
You can specify the following compact
options:
compact
: The name of the collection you want to run compaction on.dryRun
: If set totrue
, returns an estimate of how much space, in bytes, compaction can reclaim from the targeted collection. IfdryRun
is enabled, thecompact
command doesn’t perform any kind of compaction and only returns the estimated value.force
: (Optional) If enabled, forcescompact
to run on the primary member of your replica set.freeSpaceTargetMB
: (Optional) Specifies the minimum amount of...