{
  "id": "mongodb/transaction-abort-due-to-write-conflict",
  "signature": "MongoServerError: Transaction 1234 was aborted due to a write conflict",
  "signature_zh": "MongoServerError：事务 1234 因写入冲突而中止",
  "regex": "MongoServerError: Transaction \\d+ was aborted due to a write conflict",
  "domain": "mongodb",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Two concurrent transactions attempted to modify the same document, causing one to abort due to optimistic concurrency control.",
  "root_cause_type": "generic",
  "root_cause_zh": "两个并发事务尝试修改同一文档，导致一个事务因乐观并发控制而中止。",
  "versions": [
    {
      "version": "mongodb-5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "mongodb-6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "mongodb-7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "mongodb-8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Disabling transactions entirely removes atomicity guarantees for multi-document operations.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Increasing wtimeoutMS does not resolve write conflicts; it only affects write concern timeouts.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Setting retryWrites=true does not apply to transactions; transactions must be retried manually.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Implement a retry loop in the application: catch the write conflict error and re-run the transaction up to 3 times with exponential backoff.",
      "success_rate": 0.85,
      "how": "Implement a retry loop in the application: catch the write conflict error and re-run the transaction up to 3 times with exponential backoff.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Reduce transaction scope by accessing fewer documents or using smaller batch sizes to minimize contention.",
      "success_rate": 0.75,
      "how": "Reduce transaction scope by accessing fewer documents or using smaller batch sizes to minimize contention.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a deterministic ordering for document updates within transactions to prevent deadlocks and conflicts.",
      "success_rate": 0.8,
      "how": "Use a deterministic ordering for document updates within transactions to prevent deadlocks and conflicts.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Implement a retry loop in the application: catch the write conflict error and re-run the transaction up to 3 times with exponential backoff.",
    "Reduce transaction scope by accessing fewer documents or using smaller batch sizes to minimize contention.",
    "Use a deterministic ordering for document updates within transactions to prevent deadlocks and conflicts."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.mongodb.com/docs/manual/core/transactions-production-consideration/#write-conflicts",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-06-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}