# MongoServerError: Can't find index: { "geometry" : "2dsphere" } for namespace test.places

- **ID:** `mongodb/geo-2dsphere-index-missing`
- **Domain:** mongodb
- **Category:** config_error
- **Error Code:** `17067`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

A geospatial query or operation requires a 2dsphere index on the geometry field, but the index does not exist or is incorrectly defined.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| mongodb-3.6 | active | — | — |
| mongodb-4.0 | active | — | — |
| mongodb-4.2 | active | — | — |
| mongodb-4.4 | active | — | — |
| mongodb-5.0 | active | — | — |
| mongodb-6.0 | active | — | — |
| mongodb-7.0 | active | — | — |

## Workarounds

1. **Create a 2dsphere index on the geometry field: `db.places.createIndex({geometry:'2dsphere'})`. Ensure the field contains valid GeoJSON objects.** (95% success)
   ```
   Create a 2dsphere index on the geometry field: `db.places.createIndex({geometry:'2dsphere'})`. Ensure the field contains valid GeoJSON objects.
   ```
2. **If the field name is wrong, update the query to use an existing 2dsphere index. Check existing indexes with `db.places.getIndexes()` and adjust the query field accordingly.** (85% success)
   ```
   If the field name is wrong, update the query to use an existing 2dsphere index. Check existing indexes with `db.places.getIndexes()` and adjust the query field accordingly.
   ```
3. **If the data is legacy coordinate pairs, convert them to GeoJSON format using an aggregation pipeline with $addFields and $project, then create the 2dsphere index. Example: `db.places.aggregate([{$addFields:{geometry:{type:'Point',coordinates:['$lon','$lat']}}},{$out:'places'}]); db.places.createIndex({geometry:'2dsphere'})`** (80% success)
   ```
   If the data is legacy coordinate pairs, convert them to GeoJSON format using an aggregation pipeline with $addFields and $project, then create the 2dsphere index. Example: `db.places.aggregate([{$addFields:{geometry:{type:'Point',coordinates:['$lon','$lat']}}},{$out:'places'}]); db.places.createIndex({geometry:'2dsphere'})`
   ```

## Dead Ends

- **** — 2d index only supports legacy coordinate pairs, not GeoJSON objects like 'Point' or 'Polygon'. (30% fail)
- **** — This does not create the required index; the query still fails. (10% fail)
- **** — The index must be on the exact field used in the query's $near or $geoWithin. (25% fail)
