{
  "id": "mongodb/change-stream-resume-from-before-drop",
  "signature": "MongoServerError: ChangeStream: resume token from before the collection drop is invalid",
  "signature_zh": "MongoServerError: ChangeStream: 来自集合删除之前的恢复令牌无效",
  "regex": "ChangeStream: resume token from before the collection drop is invalid",
  "domain": "mongodb",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A change stream attempted to resume using a resume token that predates a collection drop, which invalidates the token because the namespace was recreated.",
  "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The drop event changes the namespace's history, making pre-drop tokens invalid.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Resume tokens are tied to the namespace and oplog position.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The error is caused by the drop event, not by oplog expiration.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Listen for 'drop' events in the change stream cursor and save a new resume token after the collection is recreated: const cursor = db.watch(); cursor.on('change', (change) => { if (change.operationType === 'drop') { // wait for collection recreation and save new token } })",
      "success_rate": 0.85,
      "how": "Listen for 'drop' events in the change stream cursor and save a new resume token after the collection is recreated: const cursor = db.watch(); cursor.on('change', (change) => { if (change.operationType === 'drop') { // wait for collection recreation and save new token } })",
      "condition": "",
      "sources": []
    },
    {
      "action": "Restart the change stream from the latest event after a drop by not providing a resume token: db.watch() without resumeAfter",
      "success_rate": 0.95,
      "how": "Restart the change stream from the latest event after a drop by not providing a resume token: db.watch() without resumeAfter",
      "condition": "",
      "sources": []
    },
    {
      "action": "Store the resume token in a separate collection and implement a fallback to start from 'now' if the token is invalid: try { db.watch({ resumeAfter: savedToken }) } catch (e) { if (e.code === 280) { db.watch() } }",
      "success_rate": 0.9,
      "how": "Store the resume token in a separate collection and implement a fallback to start from 'now' if the token is invalid: try { db.watch({ resumeAfter: savedToken }) } catch (e) { if (e.code === 280) { db.watch() } }",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Listen for 'drop' events in the change stream cursor and save a new resume token after the collection is recreated: const cursor = db.watch(); cursor.on('change', (change) => { if (change.operationType === 'drop') { // wait for collection recreation and save new token } })",
    "Restart the change stream from the latest event after a drop by not providing a resume token: db.watch() without resumeAfter",
    "Store the resume token in a separate collection and implement a fallback to start from 'now' if the token is invalid: try { db.watch({ resumeAfter: savedToken }) } catch (e) { if (e.code === 280) { db.watch() } }"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.mongodb.com/docs/manual/changeStreams/",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-03-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}