On this page本页内容
$minDistance
Filters the results of a geospatial 将地理空间$near or $nearSphere query to those documents that are at least the specified distance from the center point.$near或$nearSphere查询的结果筛选到距离中心点至少指定距离的文档。
If 如果$near or $nearSphere query specifies the center point as a GeoJSON point, specify the distance as a non-negative number in meters.$near或$nearSphere查询将中心点指定为GeoJSON点,请将距离指定为以米为单位的非负数。
If 如果$nearSphere query specifies the center point as legacy coordinate pair, specify the distance as a non-negative number in radians. $nearSphere查询将中心点指定为传统坐标对,请将距离指定为以弧度表示的非负数。如果查询将中心点指定为GeoJSON点,则$near can only use the 2dsphere index if the query specifies the center point as a GeoJSON point.$near只能使用2dsphere索引。
$near$near一起使用If specifying latitude and longitude coordinates, list the longitude first and then latitude:如果指定纬度和经度坐标,请先列出经度,然后列出纬度:
-180 and 180, both inclusive.-180和180之间(包括两者)。-90 and 90, both inclusive.-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
}
}
}
)
$nearSphere$nearSphere一起使用Consider a collection 考虑一个集合places that contains documents with a location field and has a 2dsphere index.places,其中包含具有location字段和2dsphere索引的文档。
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