Skip to main content

Compaction

Compaction rebuilds collection storage to remove fragmentation and then rebuilds indexes.

db.compactCollection(name)

compactCollection(name: string): Promise<void>

db.compactAll()

compactAll(): Promise<void>

collection.compact()

compact(): Promise<void>

The compaction engine performs:

  1. crash recovery checks
  2. snapshot rebuild to a temporary directory
  3. atomic directory swap
  4. reopen DB
  5. rebuild indexes