<!-- llms-explorer concept facts · https://llms-explorer.com/tree/mongodb-8-0-autocompact-background-compaction-on-atlas/ · pack 2026-10-23 · ~2108 tokens -->

# MongoDB 8.0 autoCompact background compaction on Atlas

> Source-anchored research for MongoDB 8.0 autoCompact background compaction on Atlas. Run status: COMPLETED.

Parent: [Atlas storage auto-scaling and disk reclaim via compact](https://llms-explorer.com/tree/atlas-storage-auto-scaling-and-disk-reclaim-via-compact/) · 6 facets · 20 facts · page: https://llms-explorer.com/tree/mongodb-8-0-autocompact-background-compaction-on-atlas/

## How it works

- When enabled, autoCompact iterates over available files and attempts to return unneeded disk space to the operating system. This supports file-space reclamation; these sources do not establish that it automatically shrinks provisioned Atlas storage or lowers its bill. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- The Atlas changelog dates the addition of the autoCompact privilege action for dedicated MongoDB 8.0+ clusters to 2 April 2025. Server availability in MongoDB 8.0 alone therefore does not establish when Atlas exposed the privilege. (medium confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)

## How-to and procedures

- Configure the Atlas database user with the `autoCompact` privilege; the current command reference specifies the `autoCompact` built-in role for authenticated Atlas users. The April 2025 Atlas changelog says the `autoCompact` privilege action allows users with the `atlasAdmin` role to enable background compaction on dedicated clusters running MongoDB 8.0+. (high confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)

## Measurements and reference values

- freeSpaceTargetMB is the minimum recoverable space required before compaction proceeds, with a documented default of 20 MB. Check $collStats with storageStats:{} and freeStorageSize first; space below the threshold makes background compaction ineffective. The threshold is not a guarantee of bytes recovered. (low confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)

## Problems, failure modes and limitations

- WT-18720, created 22 September 2026 and updated 21 October 2026, contains an external reporter's claim that autoCompact relocation I/O has no rate limit and can trigger storage-watchdog kills on constrained disks. The issue is unresolved and lists neither affected versions nor an Atlas-specific reproduction; treat it as an investigation lead, not proof that every Atlas 8.0 cluster is affected. (low confidence) (verified as of 2026-10-21) — [source](https://jira.mongodb.org/browse/WT-18720)
- Connect directly to every intended node and issue the command against admin, for example db.getSiblingDB("admin").runCommand({autoCompact:true, freeSpaceTargetMB:20, runOnce:false}). The primary does not replicate autoCompact to secondaries; mongos cannot execute it, so sharded deployments require node connections within each shard. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- To change an active background-compaction configuration, first issue {autoCompact:false}, then re-enable with the new options. Reissuing autoCompact while background compaction is active returns an error; SERVER-90499 records the historically confusing WiredTigerKVEngine::autoCompact() 22: Invalid argument error and a fix targeted at 8.0.0-rc9. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- Compaction introduces checkpoint synchronization overhead and can delay or prevent backups on busy databases. The autoCompact manual recommends low-traffic periods and disabling compaction before a backup; the compact reference gives the same checkpoint warning. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)

## Comparisons and alternatives

- The primary does not replicate autoCompact to secondaries. The command targets mongod rather than mongos; in sharded deployments operators must address shard nodes separately. Reads and writes can continue, and secondaries can continue replication. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- MongoDB 8.0 introduced autoCompact, which enables a background process that periodically visits collection files and attempts compaction when enough space is recoverable. It automates space reclamation within existing storage rather than provisioning more disk capacity. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- Treat reclaimed bytes as workload- and file-layout-dependent rather than guaranteed: MongoDB describes compaction as an attempt and says effectiveness depends on available blocks and their location. Mydbops independently recommends considering initial sync because compaction does not guarantee recovery of all expected space; its general recommendation is not an Atlas autoCompact benchmark. (medium confidence) — [source](https://www.mongodb.com/docs/atlas/reference/faq/storage.md)

## Facts and statements

- MongoDB introduced autoCompact in 8.0. Atlas announced its background-compaction privilege on 2 April 2025 for dedicated clusters running MongoDB 8.0+; current documentation excludes M0 and Flex. (high confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- For Atlas, configure the autoCompact database-user privilege, connect to each node intended for compaction, and issue db.runCommand({autoCompact:true}) on the admin database. The server manual names the Atlas autoCompact built-in role as the required role. (high confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- runOnce:true requests one traversal of collections on the node; runOnce:false requests continuous compaction. In continuous mode a collection that fails compaction is skipped temporarily and retried after approximately an hour. The oplog is excluded. (low confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- Stop an active background-compaction operation with db.runCommand({autoCompact:false}) before restarting it with different options. SERVER-90499 records an Atlas attempt that returned WiredTigerKVEngine::autoCompact() 22: Invalid argument while reconfiguring; the issue lists a fix in 8.0.0-rc9 and 8.1.0-rc0. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- A mongod restart does not preserve command-enabled background compaction by default: enableAutoCompaction defaults to disabled, so autoCompact must be enabled again after restart. The manual also describes setting enableAutoCompaction at mongod startup; that self-managed startup option does not establish that Atlas exposes it to customers. (low confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- Background compaction still incurs work: MongoDB recommends low-traffic periods and warns that repeated checkpoints can delay or prevent backups. Disable compaction before taking a backup. A separate September 2026 issue reports I/O saturation and tail-latency degradation, reinforcing the need to measure production impact. (medium confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- Atlas documents autoCompact support on dedicated clusters running MongoDB 8.0 or later; M0 and Flex clusters do not support the command. (high confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- Reads and writes remain permitted during autoCompact, and secondaries can continue replication. Background compaction excludes the oplog. These concurrency properties do not promise zero performance impact. (low confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
- For a particular collection, use compact directly; MongoDB 8.0 adds compact dryRun:true to estimate reclaimable bytes before performing compaction. autoCompact instead automates traversal across files. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/autoCompact.md)
