mongodb runtime_error ai_generated true

MongoServerError: Transaction aborted due to a catalog operation

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

Also available as: JSON · Markdown · 中文
85%Fix Rate
90%Confidence
1Evidence
2024-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
MongoDB 4.2.24 active
MongoDB 5.0.18 active
MongoDB 6.0.8 active

Root Cause

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

generic

中文

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

Official Documentation

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

Workarounds

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

中文步骤

  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.

Dead Ends

Common approaches that don't work:

  1. 90% fail

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

  2. 95% fail

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