# MongoServerError: Can't extract geo keys: 2dsphere index requires 'Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', or 'MultiPolygon' GeoJSON type, but found 'GeometryCollection'

- **ID:** `mongodb/geo-index-2dsphere-unsupported-type`
- **Domain:** mongodb
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 92%

## Root Cause

A 2dsphere index cannot index a GeoJSON GeometryCollection directly; it must be decomposed into individual geometries.

## Version Compatibility

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

## Workarounds

1. **Convert GeometryCollection to an array of individual geometries in the document: update the field to an array like {loc: [{type: 'Point', coordinates: [0,0]}, {type: 'LineString', coordinates: [[1,1],[2,2]]}]} and create a 2dsphere index on the array field.** (90% success)
   ```
   Convert GeometryCollection to an array of individual geometries in the document: update the field to an array like {loc: [{type: 'Point', coordinates: [0,0]}, {type: 'LineString', coordinates: [[1,1],[2,2]]}]} and create a 2dsphere index on the array field.
   ```
2. **Remove the GeometryCollection document or skip it using a $match stage before the $geoNear stage in aggregation.** (85% success)
   ```
   Remove the GeometryCollection document or skip it using a $match stage before the $geoNear stage in aggregation.
   ```

## Dead Ends

- **** — Creating a sparse index does not bypass the type check; it only skips documents without the field. (95% fail)
- **** — Using $geoNear with an aggregation pipeline fails with the same error because the index is still applied. (90% fail)
