我有一个数据库,其中只有我的文件Points
。我考虑添加一个地理空间索引。所以我可以从2dsphere和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
二维索引支持:
- 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]
}
或二维索引:
location : [10,45]
我的问题归结为哪个更快?我真的不知道如何衡量它。
问题假设我只想查询一个正方形box
数据并且不关心复杂的多边形搜索:要么使用仅受二维索引支持的$box (如果我没看错的话),要么使用$geoWithin的$polygon方法两个索引都支持。