On this page本页内容
$geoWithin
¶Selects documents with geospatial data that exists entirely within a specified shape.选择包含完全存在于指定形状中的地理空间数据的文档。
The specified shape can be either a GeoJSON Polygon (either single-ringed or multi-ringed), a GeoJSON MultiPolygon, or a shape defined by legacy coordinate pairs. 指定的形状可以是GeoJSON多边形(单环或多环)、GeoJSON多多边形或由传统坐标对定义的形状。The $geoWithin
operator uses the $geometry
operator to specify the GeoJSON object.$geoWithin
运算符使用$geometry
运算符指定GeoJSON对象。
To specify a GeoJSON polygons or multipolygons using the default coordinate reference system (CRS), use the following syntax:要使用默认坐标系(CRS)指定GeoJSON多边形或多多边形,请使用以下语法:
For 对于指定面积大于一个半球的GeoJSON几何图形的$geoWithin
queries that specify GeoJSON geometries with areas greater than a single hemisphere, the use of the default CRS results in queries for the complementary geometries.$geoWithin
查询,使用默认CRS会导致查询互补几何图形。
To specify a single-ringed GeoJSON polygon with a custom MongoDB CRS, use the following prototype that specifies the custom MongoDB CRS in the 要指定带有自定义MongoDB CRS的单环形GeoJSON多边形,请使用以下原型在$geometry
expression:$geometry
表达式中指定自定义MongoDB CRS:
The custom MongoDB CRS uses a counter-clockwise winding order and allows 自定义MongoDB CRS使用逆时针缠绕顺序,并允许$geoWithin
to support queries with a single-ringed GeoJSON polygon whose area is greater than or equal to a single hemisphere. $geoWithin
支持使用面积大于或等于单个半球的单个环形GeoJSON多边形的查询。If the specified polygon is smaller than a single hemisphere, the behavior of 如果指定的多边形小于单个半球,则$geoWithin
with the MongoDB CRS is the same as with the default CRS. $geoWithin
在MongoDB CRS中的行为与默认CRS相同。See also “Big” Polygons.另请参见“大”多边形。
If querying for inclusion in a shape defined by legacy coordinate pairs on a plane, use the following syntax:如果查询平面上由传统坐标对定义的形状中是否包含,请使用以下语法:
The available shape operators are:可用的形状运算符包括:
$box
,$polygon
,$center
$centerSphere
Important重要的
If you use longitude and latitude, specify coordinates in order of 如果使用经度和纬度,请按longitude, latitude
.longitude, latitude
的顺序指定坐标。
$geoWithin
does not require a geospatial index. $geoWithin
不需要地理空间索引。However, a geospatial index will improve query performance. 然而,地理空间索引将提高查询性能。Both 2dsphere and 2d geospatial indexes support 2dsphere和2d地理空间索引都支持$geoWithin
.$geoWithin
。
The $geoWithin
operator does not return sorted results. $geoWithin
运算符不返回排序结果。As such, MongoDB can return 因此,MongoDB可以比对结果进行排序的地理空间$geoWithin
queries more quickly than geospatial $near
or $nearSphere
queries, which sort results.$near
或$nearSphere
查询更快地返回$geoWithin
查询。
$geoWithin
does not guarantee that it will consider a piece of geometry to contain its component geometry, or another polygon sharing its component geometry.$geoWithin
不保证它会考虑一块几何结构来包含它的组件几何结构,或者另一个多边形共享它的组件几何结构。
For 对于$geoWithin
, if you specify a single-ringed polygon that has an area greater than a single hemisphere, include the custom MongoDB coordinate reference system in the $geometry
expression; otherwise, $geoWithin
queries for the complementary geometry. $geoWithin
,如果指定了一个面积大于单个半球的环形多边形,请在$geometry
表达式中包含自定义MongoDB坐标参考系;否则,$geoWithin
查询将用于互补几何体。For all other GeoJSON polygons with areas greater than a hemisphere, 对于面积大于半球的所有其他GeoJSON多边形,$GeoInside将查询互补几何体。$geoWithin
queries for the complementary geometry.
The following example selects all 以下示例选择完全存在于GeoJSON多边形中的所有loc
data that exist entirely within a GeoJSON Polygon. loc
数据。The area of the polygon is less than the area of a single hemisphere:多边形的面积小于单个半球的面积:
For single-ringed polygons with areas greater than a single hemisphere, see Within a “Big” Polygon.有关面积大于单个半球的单环形多边形,请参阅“大”多边形内。
To query with a single-ringed GeoJSON polygon whose area is greater than a single hemisphere, the 要使用面积大于单个半球的单个环形GeoJSON多边形进行查询,$geometry
expression must specify the custom MongoDB coordinate reference system. $geometry
表达式必须指定自定义MongoDB坐标参考系。For example:例如:
$within
¶Deprecated since version 2.4:自2.4版以来已弃用:$geoWithin
replaces $within
in MongoDB 2.4.$geoWithin
取代MongoDB 2.4中的$within
。