定义
$minDistance过滤地理空间
$near或$nearSphere查询的结果,以查找与点至少相距指定距离的文档。如果
$near或$nearSphere查询将中心点指定为GeoJSON point,请将距离指定为以米为单位的非负数。如果
$nearSphere查询将中心点指定为传统坐标对,则将距离指定为以弧度为单位的非负数。 仅当query将中心点指定为 GeoJSON$nearpoint 时, 才能使用 2dsphere 索引。
示例
与 $near
重要
如果指定纬度和经度坐标,则先列出经度,然后列出纬度。
有效经度值介于
-180和180之间,两者均包括在内。有效纬度值介于
-90和90之间,两者均包括在内。
考虑一个有 2dsphere 索引的集合 places。
以下示例返回距指定 GeoJSON 点至少 1000 米、至多 5000 米的文档(按从最近到最远排序):
db.places.find( { location: { $near : { $geometry: { type: "Point", coordinates: [ -73.9667, 40.78 ] }, $minDistance: 1000, $maxDistance: 5000 } } } )
与 $nearSphere
考虑一个 places 集合,它包含带有 location 字段的文档且具有 2dsphere 索引。
然后,以下示例返回距指定点至少 1000 米、至多 5000 米(按从最近到最远排序)的 location:
db.places.find( { location: { $nearSphere: { $geometry: { type : "Point", coordinates : [ -73.9667, 40.78 ] }, $minDistance: 1000, $maxDistance: 5000 } } } )
有关将中心点指定为传统坐标对的示例,请参阅 $nearSphere