문서 메뉴

문서 홈MongoDB 실행 및 관리MongoDB Atlas

$searchMeta

이 페이지의 내용

  • 구문
  • 필드
  • 행동
  • 메타데이터 결과 유형
  • 예제
  • 문제 해결
$searchMeta

The $searchMeta stage returns different types of metadata result documents.

참고

To run $searchMeta queries over sharded collections, your cluster must run MongoDB v6.0 or later.

$searchMeta 파이프라인 단계의 프로토타입 형식은 다음과 같습니다.

{
$searchMeta: {
"index": "<index-name>",
"<collector-name>"|"<operator-name>": {
<collector-specification>|<operator-specification>
},
"count": {
<count-options>
}
}
}

$searchMeta 단계에서는 다음 필드가 있는 문서를 사용합니다.

필드
유형
필요성
설명
<collector-name>
객체
조건부
쿼리에 사용할 컬렉터의 이름입니다. 이 필드의 값으로 콜렉터별 옵션이 포함된 문서를 제공할 수 있습니다. 정의된 패싯 이름과 해당 패싯에 대한 버킷 배열의 매핑을 검색하려면 값이 facet여야 합니다. 자세한 사항은 패싯을 참조하십시오. 이 값 또는 <operator-name>를 지정해야 합니다.
count
객체
옵션
결과의 개수를 검색하기 위한 수량 옵션을 지정하는 문서입니다. 자세한 내용은 Atlas Search 결과 수량을 참조하세요.
index
문자열
옵션

사용할 Atlas Search 인덱스의 이름입니다. 생략하면 기본값은 default입니다.

인덱스 이름의 철자가 틀렸거나 지정된 인덱스가 클러스터에 존재하지 않는 경우 Atlas Search는 결과를 반환하지 않습니다.

<operator-name>
객체
조건부
Name of the operator to search with. You can provide a document that contains the operator-specific options as the value for this field. You must specify this or <collector-name>. $searchMeta returns the default count metadata only.

The $searchMeta stage must be the first stage in any pipeline.

The structure of the metadata results document that is returned by the $searchMeta stage varies based on the type of results. Atlas Search supports the following result types:

유형
결과 구조
count
결과에 포함된 개수 결과는 결과에 반환된 개수가 검색 결과의 총 개수인지 또는 하한인지를 나타냅니다. 자세한 내용은 개수 결과를 참조하세요.
facet
패싯 쿼리에 대한 결과는 정의된 패싯 이름을 해당 패싯의 버킷 배열에 매핑하는 것입니다. 자세한 사항은 패싯 결과를 참조하십시오.

sample_mflix.movies collection에 대한 다음 인덱스를 가정합니다.

{
"mappings": {
"dynamic": false,
"fields": {
"year": {
"type": "number"
}
}
}
}

The following query searches for the number of movies released in 1998 using the $searchMeta stage.

db.movies.aggregate([
{
"$searchMeta": {
"range": {
"path": "year",
"gte": 1998,
"lt": 1999
},
"count": {
"type": "total"
}
}
}
])
[ { count: { total: Long("552") } } ]

Atlas Search $search 쿼리에 문제가 있는 경우 Atlas 검색 오류 문제 해결을 참조하세요.

← $search