# MongoServerError：更改流错误：来自WiredTiger的恢复令牌已过期：令牌时间戳1234567890早于最旧时间戳1234567895

- **ID:** `mongodb/change-stream-resume-token-wiredtiger-stale`
- **领域:** mongodb
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

由于检查点或复制压力导致存储引擎的最旧时间戳超过了恢复令牌时间戳，该令牌已从WiredTiger的历史记录中被修剪。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| mongodb 6.0 | active | — | — |
| mongodb 7.0 | active | — | — |
| mongodb 8.0 | active | — | — |

## 解决方案

1. ```
   Increase the oplog size to retain more history: `db.adminCommand({ replSetResizeOplog: 1, size: 40960 })` (40GB) and use `db.adminCommand({ setParameter: 1, minSnapshotHistoryWindowInSeconds: 3600 })` to keep WiredTiger snapshots for 1 hour.
   ```
2. ```
   Implement fallback logic in the application: on this error, start a new change stream from the current time using `db.collection.watch([], { startAfter: resumeToken })` or `{ startAtOperationTime: Timestamp(...) }` and reprocess recent events.
   ```
3. ```
   Reduce the resume token interval by polling change streams more frequently (e.g., every 5 seconds instead of 30 seconds) to keep tokens within the retention window.
   ```

## 无效尝试

- **** — The token is already pruned from the oplog and WiredTiger; retrying with the same token will result in the same error. (95% 失败率)
- **** — Checkpoint frequency does not directly control timestamp pruning; the oldest timestamp is managed by replication and read concern settings. (80% 失败率)
- **** — This is not configurable and would break point-in-time read operations; the error is a symptom of a broader retention issue. (90% 失败率)
