Definition定义
$minDistanceFilters the results of a geospatial将地理空间$nearor$nearSpherequery to those documents that are at least the specified distance from the center point.$near或$nearSphere查询的结果筛选到距离中心点至少指定距离的文档。If如果$nearor$nearSpherequery specifies the center point as a GeoJSON point, specify the distance as a non-negative number in meters.$near或$nearSphere查询将中心点指定为GeoJSON点,请将距离指定为非负数(单位为米)。If如果$nearSpherequery specifies the center point as legacy coordinate pair, specify the distance as a non-negative number in radians.$nearSphere查询将中心点指定为传统坐标对,请将距离指定为非负数(以弧度为单位)。如果查询将中心点指定为GeoJSON点,$nearcan only use the 2dsphere index if the query specifies the center point as a GeoJSON point.$near只能使用2dsphere索引。
Examples示例
Use with $near使用$near
$nearImportant
If specifying latitude and longitude coordinates, list the longitude first, and then latitude.如果指定纬度和经度坐标,请先列出经度,然后再列出纬度。
Valid longitude values are between有效的经度值介于-180and180, both inclusive.-180和180之间,包括-180和180。Valid latitude values are between有效的纬度值介于-90and90, both inclusive.-90和90之间,包括-90和90。
Consider a collection 考虑一个具有places that has a 2dsphere index.2dsphere索引的集合places。
The following example returns documents that are at least 以下示例返回距离指定GeoJSON点至少1000 meters from and at most 5000 meters from the specified GeoJSON point, sorted from nearest to farthest:1000米、最多5000米的文档,从最近到最远排序:
db.places.find(
{
location:
{ $near :
{
$geometry: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
$minDistance: 1000,
$maxDistance: 5000
}
}
}
)Use with $nearSphere与$nearSphere一起使用
$nearSphereConsider a collection 考虑一个包含具有places that contains documents with a location field and has a 2dsphere index.location字段的文档并具有2dsphere索引的集合places。
Then, the following example returns whose 然后,以下示例返回其location is at least 1000 meters from and at most 5000 meters from the specified point, ordered from nearest to farthest:location距离指定点至少1000米,最多5000米,从最近到最远排序:
db.places.find(
{
location: {
$nearSphere: {
$geometry: {
type : "Point",
coordinates : [ -73.9667, 40.78 ]
},
$minDistance: 1000,
$maxDistance: 5000
}
}
}
)
For an example that specifies the center point as legacy coordinate pair, see 有关将中心点指定为传统坐标对的示例,请参阅$nearSphere$nearSphere