지역 검색
geoSearch
중요
MongoDB 5.0에서 제거됨
MongoDB 5.0 removes the deprecated geoHaystack index and
geoSearch
command. Use a 2d index with$geoNear
or one of the supported geospatial query operators instead.MongoDB 인스턴스를 5.0으로 업그레이드하고 featureCompatibilityVersion을
5.0
로 설정하면 기존의 모든 geoHaystack 인덱스가 삭제됩니다.The
geoSearch
command provides an interface to MongoDB's haystack 인덱스 functionality. These indexes are useful for returning results based on location coordinates after collecting results based on some other query (i.e. a "haystack.")The
geoSearch
command accepts a 문서 that contains the following fields.필드유형설명geoSearch
문자열
The collection to query.
search
문서
Query to filter documents.
near
배열
Coordinates of a point.
maxDistance
숫자
Optional. Maximum distance from the specified point.
limit
숫자
Optional. Maximum number of documents to return.
readConcern
문서
선택 사항. 읽기 고려를 지정합니다.
readConcern
옵션의 구문은 다음과 같습니다.readConcern: { level: <value> }
가능한 읽기 고려 수준은 다음과 같습니다.
"local"
. This is the default read concern level for read operations against the primary and secondaries."available"
입니다. 프라이머리 및 세컨더리에 대한 읽기 작업에 사용할 수 있습니다."available"
은 프라이머리 및 비 샤드형 세컨더리에 대해"local"
과 동일하게 동작합니다. 쿼리는 인스턴스의 가장 최근 데이터를 반환합니다."majority"
. WiredTiger 스토리지 엔진을 사용하는 복제본 세트에 사용할 수 있습니다."linearizable"
.primary
의 읽기 작업에만 사용할 수 있습니다.
읽기 고려 수준에 대한 자세한 내용은 읽기 고려 수준을 참조하세요.
For more information on the read concern levels, see 읽기 고려 수준.
comment
any
선택 사항. 이 명령에 첨부할 사용자 제공 코멘트입니다. 설정되면 이 설명은 다음 위치에서 이 명령의 레코드와 함께 표시됩니다.
mongod 로그 메시지(
attr.command.cursor.comment
필드).데이터베이스 프로파일러 출력의
command.comment
필드에 있습니다.currentOp
{command.comment
5} 필드에 출력을 입력합니다.
댓글은 유효한 모든 BSON types (문자열, 정수, 객체, 배열 등)이 될 수 있습니다.
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
중요
이 명령은 서버리스 인스턴스에서는 지원되지 않습니다. 자세한 내용은 지원되지 않는 명령을 참조하세요.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
행동
Limit
Unless specified otherwise, the geoSearch
command
limits results to 50 documents.
샤딩된 클러스터
geoSearch
is not supported for sharded clusters.
트랜잭션
geoSearch
는 분산 트랜잭션 내에서 사용할 수 있습니다.
중요
대부분의 경우 분산 트랜잭션은 단일 문서 쓰기에 비해 더 큰 성능 비용이 발생하므로 분산 트랜잭션의 가용성이 효과적인 스키마 설계를 대체할 수는 없습니다. 대부분의 시나리오에서 비정규화된 데이터 모델 (내장된 문서 및 배열) 은 계속해서 데이터 및 사용 사례에 최적일 것입니다. 즉, 대부분의 시나리오에서 데이터를 적절하게 모델링하면 분산 트랜잭션의 필요성이 최소화됩니다.
추가 트랜잭션 사용 고려 사항(예: 런타임 제한 및 oplog 크기 제한)은 프로덕션 고려사항을 참조하세요.
예시
다음 예를 고려하십시오.
db.runCommand({ geoSearch : "places", near: [ -73.9667, 40.78 ], maxDistance : 6, search : { type : "restaurant" }, limit : 30 })
The above command returns all documents with a type
of
restaurant
having a maximum distance of 6 units from the
coordinates [ -73.9667, 40.78 ]
in the collection places
up to a
maximum of 30 results.
기본 읽기 고려 재정의
기본 읽기 문제 수준인 "local"
를 재정의하려면 readConcern
옵션을 사용하십시오.
복제본 세트에 대한 다음 작업은 대부분의 노드에 기록된 것으로 확인된 데이터의 가장 최근 복제본을 읽을 수 있도록 "majority"
의 읽기 고려를 지정합니다.
참고
읽기 고려 수준에 관계없이 노드의 최신 데이터는 시스템에 있는 데이터의 최신 버전을 반영하지 않을 수 있습니다.
db.runCommand( { geoSearch: "places", near: [ -73.9667, 40.78 ], search : { type : "restaurant" }, readConcern: { level: "majority" } } )
단일 스레드가 자신의 쓰기를 읽을 수 있도록 하려면 복제본 세트의 프라이머리에 대해 "majority"
읽기 고려 및 "majority"
쓰기 고려를 사용합니다.