Storage Engine Overview
Version Compatibility
| Component | Description |
|---|---|
| MongoDB version | 6.0 / 7.0 / 8.0 |
| 6.1+ journaling | Permanently enabled |
| InMemory engine | Enterprise edition only |
| InMemory default memory | 50%×(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
- Real-time analytics systems
- High-speed cache layer
- Session storage
- 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
- Checkpoint all tables
- Update table checkpoint metadata to WiredTiger.wt
- Rename temporary files
Journaling Mechanism
When database crashes, durability is ensured through Write Ahead Logging pre-writing to journal files on disk.