{
  "id": "mongodb/geo-index-2dsphere-invalid-point",
  "signature": "MongoServerError: Can't extract geo keys: Point must be an array or object with 'type' and 'coordinates' properties",
  "signature_zh": "MongoServerError: 无法提取地理键：点必须是包含 'type' 和 'coordinates' 属性的数组或对象",
  "regex": "Can't extract geo keys: Point must be an array or object with 'type' and 'coordinates' properties",
  "domain": "mongodb",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Documents in a collection with a 2dsphere index contain GeoJSON objects that are malformed, missing required fields (type/coordinates), or have invalid coordinate values (e.g., latitude outside ±90 or longitude outside ±180).",
  "root_cause_type": "generic",
  "root_cause_zh": "在具有 2dsphere 索引的集合中，文档包含格式错误的 GeoJSON 对象，缺少必需字段（type/coordinates），或坐标值无效（例如纬度超出 ±90 或经度超出 ±180）。",
  "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 invalid documents remain in the collection and will cause the same error when the index is rebuilt or when querying.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "2dsphere indexes only support GeoJSON format; legacy pairs require a 2d index, not 2dsphere.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Human error can introduce additional malformed data; a scripted approach is safer.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Find invalid documents using a script like: `db.collection.find({ \"loc\": { $not: { $type: \"object\" } } })` or check for missing fields: `db.collection.find({ \"loc.type\": { $exists: false } })`. Then update or remove them.",
      "success_rate": 0.9,
      "how": "Find invalid documents using a script like: `db.collection.find({ \"loc\": { $not: { $type: \"object\" } } })` or check for missing fields: `db.collection.find({ \"loc.type\": { $exists: false } })`. Then update or remove them.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `db.collection.aggregate([{ $addFields: { loc: { $cond: { if: { $eq: [{ $type: \"$loc\" }, \"array\"] }, then: { type: \"Point\", coordinates: \"$loc\" }, else: \"$loc\" } } } }, { $out: \"collection\" }])` to convert legacy arrays to GeoJSON.",
      "success_rate": 0.85,
      "how": "Use `db.collection.aggregate([{ $addFields: { loc: { $cond: { if: { $eq: [{ $type: \"$loc\" }, \"array\"] }, then: { type: \"Point\", coordinates: \"$loc\" }, else: \"$loc\" } } } }, { $out: \"collection\" }])` to convert legacy arrays to GeoJSON.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If coordinates are out of range, clamp them: `db.collection.updateMany({}, [{ $set: { \"loc.coordinates.0\": { $min: [ { $max: [ \"$loc.coordinates.0\", -180 ] }, 180 ] } } }])` (repeat for latitude).",
      "success_rate": 0.8,
      "how": "If coordinates are out of range, clamp them: `db.collection.updateMany({}, [{ $set: { \"loc.coordinates.0\": { $min: [ { $max: [ \"$loc.coordinates.0\", -180 ] }, 180 ] } } }])` (repeat for latitude).",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用脚本查找无效文档：`db.collection.find({ \"loc\": { $not: { $type: \"object\" } } })` 或检查缺失字段：`db.collection.find({ \"loc.type\": { $exists: false } })`。然后更新或删除它们。",
    "使用 `db.collection.aggregate([{ $addFields: { loc: { $cond: { if: { $eq: [{ $type: \"$loc\" }, \"array\"] }, then: { type: \"Point\", coordinates: \"$loc\" }, else: \"$loc\" } } } }, { $out: \"collection\" }])` 将旧式数组转换为 GeoJSON。",
    "如果坐标超出范围，进行钳制：`db.collection.updateMany({}, [{ $set: { \"loc.coordinates.0\": { $min: [ { $max: [ \"$loc.coordinates.0\", -180 ] }, 180 ] } } }])`（对纬度重复）。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.mongodb.com/docs/manual/geospatial-queries/",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-06-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}