{
  "id": "mongodb/geo-index-with-non-geo-query",
  "signature": "MongoServerError: Can't use geo index with non-geo query filter: expected field 'location' to be a GeoJSON object",
  "signature_zh": "MongoServerError：无法将地理索引与非地理查询过滤器一起使用：期望字段 'location' 为 GeoJSON 对象",
  "regex": "Can't use geo index with non-geo query filter",
  "domain": "mongodb",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A 2dsphere or 2d index exists on a field, but the query filter uses a non-geospatial operator (e.g., $eq, $regex) on the same field, causing type mismatch.",
  "root_cause_type": "generic",
  "root_cause_zh": "字段上存在 2dsphere 或 2d 索引，但查询过滤器在同一字段上使用了非地理空间操作符（如 $eq、$regex），导致类型不匹配。",
  "versions": [],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Removing the geo index entirely bypasses the error but degrades geospatial query performance; the error returns if the index is recreated.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changing the query to use $geoWithin or $near without converting the field data to GeoJSON format still fails with a similar error.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the field contains valid GeoJSON data (e.g., {type: 'Point', coordinates: [lng, lat]}) and use geospatial operators like $geoWithin in the query. Example: db.places.find({location: {$geoWithin: {$centerSphere: [[-73.97, 40.77], 0.01]}}})",
      "success_rate": 0.9,
      "how": "Ensure the field contains valid GeoJSON data (e.g., {type: 'Point', coordinates: [lng, lat]}) and use geospatial operators like $geoWithin in the query. Example: db.places.find({location: {$geoWithin: {$centerSphere: [[-73.97, 40.77], 0.01]}}})",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the field is not geospatial, drop the geo index and create a regular index (e.g., db.collection.createIndex({location: 1})), then use non-geo queries.",
      "success_rate": 0.85,
      "how": "If the field is not geospatial, drop the geo index and create a regular index (e.g., db.collection.createIndex({location: 1})), then use non-geo queries.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure the field contains valid GeoJSON data (e.g., {type: 'Point', coordinates: [lng, lat]}) and use geospatial operators like $geoWithin in the query. Example: db.places.find({location: {$geoWithin: {$centerSphere: [[-73.97, 40.77], 0.01]}}})",
    "If the field is not geospatial, drop the geo index and create a regular index (e.g., db.collection.createIndex({location: 1})), then use non-geo queries."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.mongodb.com/docs/manual/core/index-geospatial/",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.88,
  "resolvable": "true",
  "first_seen": "2024-03-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}