我有一个db,我的文档只有Points
。我考虑增加一个地理空间索引。所以我可以选择2dsphere和2d之一。2dsphere vs 2d索引:哪个“更好”/更快?
MongoDB.org有:
2dsphere索引支持:
- 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索引支持:
- 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
但是,因为我的所有文件都点我既可以有一个在我的模式下的选项没有太大的区别。
为2dsphere:
location : {
type : "Point" ,
coordinates : [10,45]
}
或2D指数:
location : [10,45]
我的问题归结为哪一个是更快?我真的不知道如何衡量它。
的问题假设,我只想查询数据的平方box
并不在意复杂的多边形搜索:要么与$box仅由二维索引支持(如果我正确读取)或与该$polygon方法$geoWithi n由两个索引支持。
你为什么不与两个索引类型/查询和一些数据在开发/分期的环境中测试?您应该在多次迭代中对性能进行平均以确保数据加载到RAM中,并且有更公平的比较。我预计未来会使用更新的'2dsphere'索引,但我还没有看到任何性能比较。 – Stennie