# MongoServerError: TransactionTooOldForSnapshot: Read timestamp is older than the oldest timestamp in the storage engine's snapshot history

- **ID:** `mongodb/transaction-too-old-for-snapshot`
- **Domain:** mongodb
- **Category:** resource_error
- **Error Code:** `262`
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

A multi-document transaction is using a read timestamp that has been pruned from the WiredTiger storage engine's snapshot history, typically due to long-running transactions or insufficient snapshot retention.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| mongodb-4.0 | active | — | — |
| mongodb-4.2 | active | — | — |
| mongodb-4.4 | active | — | — |
| mongodb-5.0 | active | — | — |
| mongodb-6.0 | active | — | — |
| mongodb-7.0 | active | — | — |

## Workarounds

1. **Reduce the duration of transactions by committing them faster. Break large transactions into smaller batches. Example: instead of one transaction updating 10,000 documents, use 100 transactions of 100 documents each.** (90% success)
   ```
   Reduce the duration of transactions by committing them faster. Break large transactions into smaller batches. Example: instead of one transaction updating 10,000 documents, use 100 transactions of 100 documents each.
   ```
2. **Increase the WiredTiger snapshot retention period by adjusting the `storage.wiredTiger.engineConfig.journalCompressor` or setting `eviction_dirty_target` to a higher value (requires server restart). Example: `db.adminCommand({setParameter:1,wiredTigerEngineConfig:{eviction_dirty_target:20}})`** (75% success)
   ```
   Increase the WiredTiger snapshot retention period by adjusting the `storage.wiredTiger.engineConfig.journalCompressor` or setting `eviction_dirty_target` to a higher value (requires server restart). Example: `db.adminCommand({setParameter:1,wiredTigerEngineConfig:{eviction_dirty_target:20}})`
   ```
3. **If using secondary reads, ensure the secondary's oplog window is large enough to support the transaction's read timestamp. Monitor with `rs.printSlaveReplicationInfo()` and increase oplog size if needed.** (80% success)
   ```
   If using secondary reads, ensure the secondary's oplog window is large enough to support the transaction's read timestamp. Monitor with `rs.printSlaveReplicationInfo()` and increase oplog size if needed.
   ```

## Dead Ends

- **** — This does not affect snapshot retention; the issue is the storage engine pruning old snapshots, not the transaction timing out. (20% fail)
- **** — Restarting resets the snapshot history but does not prevent pruning; the error will recur if the same pattern occurs. (10% fail)
- **** — Changing read concern may affect transaction isolation guarantees and does not address the root cause of long-running operations. (15% fail)
