23

我有一个数据库,其中只有我的文件Points。我考虑添加一个地理空间索引。所以我可以从2dsphere2d中进行选择。

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方法两个索引都支持。

4

1 回答 1

4

除了您已经完成的研究之外,只是想添加我在这两个索引之间遇到的另一个差异。

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

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

来源: MongoDB 文档参考

于 2014-12-30T04:38:35.767 回答