What Is a 2dsphere Geospatial Indexes in MongoDB?
Indexes GeoJSON geometry using a spherical model and supports geographic predicates and distance searches.
How the 2dsphere Geospatial Indexes Algorithm Works
Indexes GeoJSON geometry using a spherical model and supports geographic predicates and distance searches.
When to Use 2dsphere Geospatial Indexes
Earth-like longitude/latitude searches: near a point, within polygons, and intersecting regions.
How to Create a MongoDB 2dsphere Geospatial Indexes
Review data quality, existing structures, feature support, build time, and deployment requirements before creating an index on a production table.
db.places.createIndex({ location: "2dsphere" })2dsphere Geospatial Indexes Query Example
This example demonstrates the matching query shape. Check the execution plan to confirm that the engine can use the index.
db.places.find({ location: { $near: { $geometry: { type: "Point", coordinates: [-73.97, 40.77] }, $maxDistance: 2000 } } })Queries Supported by 2dsphere Geospatial Indexes
Earth-like longitude/latitude searches: near a point, within polygons, and intersecting regions. A similar-looking predicate may not use the same access path; operators, expressions, key order, and data type all matter.
Read Performance, Storage, and Write Costs
Geospatial keys add storage and write work; invalid geometry can fail builds. Indexes reduce some search work but require storage and add maintenance to writes.
2dsphere Geospatial Indexes Limitations and Common Mistakes
GeoJSON coordinates are longitude then latitude. Verify units and missing-field behavior.
Do not assume that an index being present means the optimizer chose it or that the query became selective.
How to Measure and Tune 2dsphere Geospatial Indexes
Validate geometry/SRID and explain representative queries; bound distance searches when appropriate.
Compare representative plans and timings before and after, including concurrent writes and realistic data volumes.
2dsphere Geospatial Indexes Questions
Will the database always use this index?
No. The optimizer weighs selectivity, estimated costs, statistics, cache state, and the amount of data returned.
What should I verify before production?
Confirm version support, query compatibility, write overhead, build/rollback procedures, and index behavior during backup and recovery.
Official MongoDB Index Documentation
Check MongoDB documentation: Index Types for release-specific requirements and supported operators.