# MongoServerError: Can't extract geo keys: invalid coordinate value: latitude out of range [-90, 90]

- **ID:** `mongodb/geo-index-coordinates-invalid`
- **Domain:** mongodb
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A document with a 2dsphere index contains a coordinate with latitude outside the valid range of -90 to 90 degrees.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| MongoDB 4.4 | active | — | — |
| MongoDB 5.0 | active | — | — |
| MongoDB 6.0 | active | — | — |

## Workarounds

1. **Query for documents with invalid coordinates using $geoNear with a large radius to identify them, then update or delete: db.places.find({ loc: { $geoWithin: { $centerSphere: [[0, 0], 3.14159] } } })** (70% success)
   ```
   Query for documents with invalid coordinates using $geoNear with a large radius to identify them, then update or delete: db.places.find({ loc: { $geoWithin: { $centerSphere: [[0, 0], 3.14159] } } })
   ```
2. **Use an aggregation pipeline to find documents where loc.coordinates[1] is outside [-90, 90] and fix them: db.places.aggregate([ { $match: { $expr: { $or: [ { $lt: [ { $arrayElemAt: ["$loc.coordinates", 1] }, -90 ] }, { $gt: [ { $arrayElemAt: ["$loc.coordinates", 1] }, 90 ] } ] } } } ])** (85% success)
   ```
   Use an aggregation pipeline to find documents where loc.coordinates[1] is outside [-90, 90] and fix them: db.places.aggregate([ { $match: { $expr: { $or: [ { $lt: [ { $arrayElemAt: ["$loc.coordinates", 1] }, -90 ] }, { $gt: [ { $arrayElemAt: ["$loc.coordinates", 1] }, 90 ] } ] } } } ])
   ```
3. **Drop the 2dsphere index, bulk update all documents to clamp coordinates to valid ranges, then recreate the index: db.places.dropIndex("loc_2dsphere"); db.places.updateMany({}, [{ $set: { "loc.coordinates.1": { $max: [ { $min: [ "$loc.coordinates.1", 90 ] }, -90 ] } } } ]); db.places.createIndex({ loc: "2dsphere" })** (90% success)
   ```
   Drop the 2dsphere index, bulk update all documents to clamp coordinates to valid ranges, then recreate the index: db.places.dropIndex("loc_2dsphere"); db.places.updateMany({}, [{ $set: { "loc.coordinates.1": { $max: [ { $min: [ "$loc.coordinates.1", 90 ] }, -90 ] } } } ]); db.places.createIndex({ loc: "2dsphere" })
   ```

## Dead Ends

- **** — The index rebuilds from the same invalid data, causing the same error. (90% fail)
- **** — The validation is part of the geospatial index specification and is version-independent. (95% fail)
- **** — MongoDB does not support custom validation for geospatial index constraints. (80% fail)
