Ι有一个数据库只有我的文件Points
.我考虑添加地理空间索引.所以我可以选择2dhere和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只支持2d索引(如果我正确读取)或者使用$ polygon方法$ geoWithi n两个索引都支持.