【发布时间】:2014-02-25 16:57:00
【问题描述】:
我有这样的文件:
{positions: [ [0.1, 0.1], [0.2, 0.2] ]}
我想查询点[0.11, 0.11]附近的文档。像这样的:
{positions: {$near: [0.11, 0.11]} }
如何添加二维索引以及如何查询?谢谢。
【问题讨论】:
-
MongoDB 手册中包含不同索引类型的geospatial tutorials。对于
2d索引,请注意坐标顺序必须始终为[longitude,latitude]。鉴于您的值看起来不像 long/lat,如果您使用不同的坐标系,您可能需要 adjust the coordinate ranges,因为默认范围是 -180 到 180(即假定 long/lat)。
标签: mongodb indexing geolocation mongodb-query