# MongoServerError: 由于目录操作导致事务中止

- **ID:** `mongodb/transaction-aborted-due-to-catalog-operation`
- **领域:** mongodb
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

在活动多文档事务涉及的命名空间上尝试了 DDL 操作（例如 createIndex、dropCollection），这是不允许的。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| MongoDB 4.2.24 | active | — | — |
| MongoDB 5.0.18 | active | — | — |
| MongoDB 6.0.8 | active | — | — |

## 解决方案

1. ```
   Move DDL operations (e.g., createIndex, drop) outside the transaction session. Perform them before starting the transaction.
   ```
2. ```
   If DDL is unavoidable, use a separate session for DDL operations and ensure they complete before the transaction starts.
   ```

## 无效尝试

- **** — Increasing transaction timeout doesn't prevent catalog operations from aborting the transaction. (90% 失败率)
- **** — Retrying the same transaction without moving DDL operations outside will fail again. (95% 失败率)
