Ι have a db where my documents are only Points
. I consider adding a geospatial index. So I can either choose from a 2dsphere and a 2d one.
MongoDB.org has:
2dsphere indexes support:
- Calculations on a sphere
- Both GeoJSON objects and legacy coordinate pairs
- A compound index with scalar index fields (i.e. ascending or
descending) as a prefix or suffix of the 2dsphere index field
2d indexes support:
- Calculations using flat geometry
- Legacy coordinate pairs (i.e., geospatial points on a flat
coordinate system)
- A compound index with only one additional field, as a suffix of
the 2d index field
However since all my documents are points I can either have one the options below in my schema without much difference.
for 2dsphere:
location : {
type : "Point" ,
coordinates : [10,45]
}
or for 2d index:
location : [10,45]
My question comes down to which one is faster? I really do not have a clue how to measure it.
The question assumes that I only want to query a square box
of data and do not care for complex polygon searches: Either with $box which is only supported by the 2d index (if I read correctly) or with the $polygon method of $geoWithin supported by both indexes.