정의
$geoWithin지정된 모양 안에만 존재하는 지리 공간적 데이터가 있는 문서를 선택합니다.
The specified shape can be either a GeoJSON
Polygon(either single-ringed or multi-ringed), a GeoJSONMultiPolygon, or a shape defined by legacy coordinate pairs. The$geoWithinoperator uses the$geometryoperator to specify the GeoJSON object.기본 좌표계(CRS)를 사용하여 GeoJSON 다각형 또는 다중 다각형을 지정하려면 다음 구문을 사용합니다.
{ <location field>: { $geoWithin: { $geometry: { type: <"Polygon" or "MultiPolygon"> , coordinates: [ <coordinates> ] } } } } For
$geoWithinqueries that specify GeoJSON geometries with areas greater than a single hemisphere, the use of the default CRS results in queries for the complementary geometries.사용자 지정 MongoDB CRS를 사용하여 단일 고리 GeoJSON 다각형을 지정하려면
$geometry표현식에 사용자 지정 MongoDB CRS를 지정하는 다음 프로토타입을 사용하세요.{ <location field>: { $geoWithin: { $geometry: { type: "Polygon" , coordinates: [ <coordinates> ], crs: { type: "name", properties: { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" } } } } } } The custom MongoDB CRS uses a counter-clockwise winding order and allows
$geoWithinto support queries with a single-ringed GeoJSON polygon whose area is greater than or equal to a single hemisphere. If the specified polygon is smaller than a single hemisphere, the behavior of$geoWithinwith the MongoDB CRS is the same as with the default CRS. See also "Big" Polygons.평면의 레거시 좌표 쌍으로 정의된 모양에 포함되도록 쿼리하는 경우 다음 구문을 사용합니다.
{ <location field>: { $geoWithin: { <shape operator>: <coordinates> } } } 사용 가능한 모양 연산자는 다음과 같습니다.
$center(원을 정의합니다), 그리고$centerSphere(구의 원을 정의합니다).
중요
경도와 위도를 사용하는 경우
longitude, latitude순으로 좌표를 지정합니다.
행동
지리 공간적 인덱스
$geoWithin 에는 지리 공간적 인덱스 필요하지 않습니다. 그러나 지리 공간적 인덱스 쿼리 성능을 향상시킵니다.2dsphere 및 2d 지리 공간적 인덱스는 모두 $geoWithin 를 지원 .
정렬되지 않은 결과
$geoWithin 연산자 정렬된 결과를 반환하지 않습니다. 따라서 MongoDB 지리 공간적 또는 $geoWithin $nearSphere 쿼리보다 $near 결과를 정렬하는 쿼리를 더 빠르게 반환할 수 있습니다.
지오메트리 퇴화
$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. For all other GeoJSON polygons with areas greater than a hemisphere, $geoWithin queries for the complementary geometry.
예시
다각형 내
다음 예시에서는 GeoJSONPolygon내에 완전히 존재하는 loc 데이터를 모두 선택합니다. 다각형의 면적이 단일 반구의 면적보다 작습니다.
db.places.find( { loc: { $geoWithin: { $geometry: { type : "Polygon" , coordinates: [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ] ] ] } } } } )
단일 반구보다 큰 면적을 가진 단일 고리 다각형의 경우 '큰' 다각형 내를 참조하세요.
"큰" 다각형 내
면적이 단일 반구보다 큰 단일 링 GeoJSON 다각형을 사용하여 쿼리하려면 $geometry 표현식에 사용자 지정 MongoDB 좌표 참조 시스템을 지정해야 합니다. 예시:
db.places.find( { loc: { $geoWithin: { $geometry: { type : "Polygon" , coordinates: [ [ [ -100, 60 ], [ -100, 0 ], [ -100, -60 ], [ 100, -60 ], [ 100, 60 ], [ -100, 60 ] ] ], crs: { type: "name", properties: { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" } } } } } } )