{
  "id": "mongodb/shard-key-not-found-in-document",
  "signature": "MongoServerError: shard key not found in document for namespace mydb.mycollection",
  "signature_zh": "MongoServerError: 在命名空间 mydb.mycollection 的文档中未找到分片键",
  "regex": "shard key not found in document for namespace .+",
  "domain": "mongodb",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "An insert or update operation attempted to modify a document in a sharded collection without including the shard key field.",
  "root_cause_type": "generic",
  "root_cause_zh": "插入或更新操作尝试修改分片集合中的文档，但未包含分片键字段。",
  "versions": [
    {
      "version": "MongoDB 4.4",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "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": "This removes the benefit of sharding; the real fix is to include the shard key in all operations.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "MongoDB does not support default values for shard keys; the field must be explicitly present in the document.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Modify the application code to always include the shard key field in insert and update operations: `db.mycollection.insert({ _id: ObjectId(), shardKeyField: value, ...otherFields })`",
      "success_rate": 0.9,
      "how": "Modify the application code to always include the shard key field in insert and update operations: `db.mycollection.insert({ _id: ObjectId(), shardKeyField: value, ...otherFields })`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `updateOne` with `upsert: true` and include the shard key in the filter to ensure it's present.",
      "success_rate": 0.85,
      "how": "Use `updateOne` with `upsert: true` and include the shard key in the filter to ensure it's present.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Modify the application code to always include the shard key field in insert and update operations: `db.mycollection.insert({ _id: ObjectId(), shardKeyField: value, ...otherFields })`",
    "Use `updateOne` with `upsert: true` and include the shard key in the filter to ensure it's present."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.mongodb.com/docs/manual/core/sharding-shard-key/",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-05-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}