{
  "id": "mongodb/sharded-cluster-query-routing-failed",
  "signature": "MongoServerError: ShardKeyNotFound: query on sharded collection test.orders did not contain shard key",
  "signature_zh": "MongoServerError：ShardKeyNotFound：对分片集合 test.orders 的查询未包含分片键",
  "regex": "MongoServerError: ShardKeyNotFound: query on sharded collection .* did not contain shard key",
  "domain": "mongodb",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A query on a sharded collection was routed to all shards (scatter-gather) because it did not include the shard key, increasing latency and load.",
  "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": "Adding an index on the query fields does not bypass the need for the shard key in targeted queries.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Disabling the balancer does not fix the query routing; it only affects chunk migration.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changing the shard key after data insertion requires re-sharding, which is a disruptive operation.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Modify the query to include the shard key in the filter to enable targeted routing (e.g., add shard key field to the query).",
      "success_rate": 0.9,
      "how": "Modify the query to include the shard key in the filter to enable targeted routing (e.g., add shard key field to the query).",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a hashed shard key to distribute data evenly and support targeted queries on the hashed value.",
      "success_rate": 0.8,
      "how": "Use a hashed shard key to distribute data evenly and support targeted queries on the hashed value.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the query cannot include the shard key, use aggregation pipelines with $merge to pre-filter data on each shard.",
      "success_rate": 0.75,
      "how": "If the query cannot include the shard key, use aggregation pipelines with $merge to pre-filter data on each shard.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Modify the query to include the shard key in the filter to enable targeted routing (e.g., add shard key field to the query).",
    "Use a hashed shard key to distribute data evenly and support targeted queries on the hashed value.",
    "If the query cannot include the shard key, use aggregation pipelines with $merge to pre-filter data on each shard."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.mongodb.com/docs/manual/core/sharding-query-isolation/",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2025-01-30",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}