gpt4 book ai didi

mongodb - 2dsphere 与 2d 索引 : which is "better"/faster?

转载 作者:IT老高 更新时间:2023-10-28 13:06:28 26 4
gpt4 key购买 nike

我有一个数据库,其中我的文档只有 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只有二​​维索引(如果我没看错的话)或 $polygon 才支持$geoWithi的方法| n 两个索引都支持。

最佳答案

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

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

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

来源: MongoDB doc reference

关于mongodb - 2dsphere 与 2d 索引 : which is "better"/faster?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21054498/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com