# MongoServerError：无法将地理索引与非地理查询过滤器一起使用：期望字段 'location' 为 GeoJSON 对象

- **ID:** `mongodb/geo-index-with-non-geo-query`
- **领域:** mongodb
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

字段上存在 2dsphere 或 2d 索引，但查询过滤器在同一字段上使用了非地理空间操作符（如 $eq、$regex），导致类型不匹配。

## 解决方案

1. ```
   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]}}})
   ```
2. ```
   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.
   ```

## 无效尝试

- **** — Removing the geo index entirely bypasses the error but degrades geospatial query performance; the error returns if the index is recreated. (85% 失败率)
- **** — Changing the query to use $geoWithin or $near without converting the field data to GeoJSON format still fails with a similar error. (80% 失败率)
