Docs 菜单

$polygon

在此页面上

$polygon

Specifies a polygon for a geospatial $geoWithin query on legacy coordinate pairs. The query returns pairs that are within the bounds of the polygon. The operator does not query for GeoJSON objects.

To define the polygon, specify an array of coordinate points:

{
<location field>: {
$geoWithin: {
$polygon: [ [ <x1> , <y1> ], [ <x2> , <y2> ], [ <x3> , <y3> ], ... ]
}
}
}

The last point is always implicitly connected to the first. You can specify as many points, i.e. sides, as you like.

重要

如果使用经度和纬度,请先指定经度。

The $polygon operator calculates distances using flat (planar) geometry.

应用程序可以在没有地理空间索引的情况下使用 $polygon。但与未编制索引的同类查询相比,地理空间索引支持更快的查询速度。

Only the 2d geospatial index supports the $polygon operator.

The following query returns all documents that have coordinates that exist within the polygon defined by [ 0 , 0 ], [ 3 , 6 ], and [ 6 , 0 ]:

db.places.find(
{
loc: {
$geoWithin: { $polygon: [ [ 0 , 0 ], [ 3 , 6 ], [ 6 , 0 ] ] }
}
}
)

在此页面上