Storage Engine Overview

Version Compatibility

ComponentDescription
MongoDB version6.0 / 7.0 / 8.0
6.1+ journalingPermanently enabled
InMemory engineEnterprise edition only
InMemory default memory50%×(RAM−1GB)

Verify Engine Commands

// View current engine
db.serverStatus().storageEngine

// View WT cache
db.serverStatus().wiredTiger.cache['maximum bytes configured']

MongoDB Supported Storage Engine Types

1. MMAPV1 Storage Engine

  • MongoDB 4.2 and earlier default storage engine
  • Uses memory-mapped file mechanism
  • Uses collection-level locking

2. WiredTiger Storage Engine

  • MongoDB 3.2 and later default storage engine
  • Document-level concurrency control
  • Supports data compression and encryption
  • Uses MVCC mechanism

3. InMemory Storage Engine

  • Enterprise edition exclusive feature
  • Completely memory-based storage solution
  • Extremely low query latency (microsecond level)

InMemory Storage Engine

Configuration Example

storage:
  engine: inMemory
  dbPath: /var/lib/mongo
  inMemory:
    engineConfig:
      inMemorySizeGB: 8

Applicable Scenarios

  1. Real-time analytics systems
  2. High-speed cache layer
  3. Session storage
  4. Financial trading systems

WiredTiger Storage Engine

Configuration Example

storage:
  dbPath: /data/mongo
  engine: wiredTiger
  wiredTiger:
    engineConfig:
      cacheSizeGB: 2
      directoryForIndexes: true
      journalCompressor: snappy

Implementation Principles

Write Request Flow

WiredTiger write operations default to writing to Cache, persisted to WAL, checkpoint every 60 seconds or when log reaches 2G.

Checkpoint Mechanism

  1. Checkpoint all tables
  2. Update table checkpoint metadata to WiredTiger.wt
  3. Rename temporary files

Journaling Mechanism

When database crashes, durability is ensured through Write Ahead Logging pre-writing to journal files on disk.