mongodb runtime_error ai_generated true

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

MongoServerError: Transaction aborted due to a catalog operation

ID: mongodb/transaction-aborted-due-to-catalog-operation

其他格式: JSON · Markdown 中文 · English
85%修复率
90%置信度
1证据数
2024-01-10首次发现

版本兼容性

版本状态引入弃用备注
MongoDB 4.2.24 active
MongoDB 5.0.18 active
MongoDB 6.0.8 active

根因分析

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

English

A DDL operation (e.g., createIndex, dropCollection) was attempted on a namespace involved in an active multi-document transaction, which is not allowed.

generic

官方文档

https://www.mongodb.com/docs/manual/core/transactions/

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 90% 失败

    Increasing transaction timeout doesn't prevent catalog operations from aborting the transaction.

  2. 95% 失败

    Retrying the same transaction without moving DDL operations outside will fail again.