2014-01-10 42 views
14

我有一个db,我的文档只有Points。我考虑增加一个地理空间索引。所以我可以选择2dsphere2d之一。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由两个索引支持。

+0

你为什么不与两个索引类型/查询和一些数据在开发/分期的环境中测试?您应该在多次迭代中对性能进行平均以确保数据加载到RAM中,并且有更公平的比较。我预计未来会使用更新的'2dsphere'索引,但我还没有看到任何性能比较。 – Stennie

回答

3

除了你已经完成的研究,只是想增加另一个差异,我遇到这两个指标之间。

默认情况下,传统坐标对上的2d索引使用26位精度,使用默认范围-180至180大致相当于2英尺或60厘米的精度。精度通过位数用于存储位置数据的geohash值。您可以配置高达32位精度的地理空间索引。

db.<collection>.ensureIndex({<location field> : "<index type>"} , { bits : <bit precision> })

来源: MongoDB doc reference