# MongoServerError: Can't use geo index with non-geo query filter: expected field 'location' to be a GeoJSON object

- **ID:** `mongodb/geo-index-with-non-geo-query`
- **Domain:** mongodb
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## 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.

## Workarounds

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]}}})** (90% success)
   ```
   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.** (85% success)
   ```
   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.
   ```

## Dead Ends

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