AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.
Docs Menu

$match (집계 단계)

$match

지정된 쿼리 조건에 따라 문서를 필터링합니다. 일치하는 문서는 다음 파이프라인 단계로 전달됩니다.

다음 환경에서 호스팅되는 배포에 $match 사용할 수 있습니다.

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
{ $match: { <query predicate> } }

$match 쿼리 조건의 구문은 find() 명령의 쿼리 인수에 사용되는 구문과 동일합니다.

쿼리 술어에 표현식을 포함하려면 $expr 연산자를 사용하세요.

$match 단계는 다음 조건 중 하나가 적용되는 경우 파이프라인 결과에서 문서 를 필터링합니다.

  • $match 쿼리 조건자는 해당 문서 에 대한 0, null 또는 false 값을 반환합니다.

  • $match 쿼리 조건자가 해당 문서 에서 누락된 필드 를 사용합니다.

  • $match 단계에서는 $where을 사용할 수 없습니다.

  • $match 단계에서 $near 또는 $nearSphere를 사용할 수 없습니다. 대신 다음 중 하나를 사용할 수 있습니다.

  • To use $text in a $match stage, the $match stage has to be the first stage of the pipeline.

    보기는 $text을(를) 지원하지 않습니다.

    참고

    $text 자체 관리(비Atlas) 배포를 위한 텍스트 쿼리 기능을 제공합니다. MongoDB 에서 호스팅되는 데이터의 경우, MongoDB 향상된 전체 텍스트 쿼리 솔루션인 MongoDB Search.도 제공합니다.

For data stored in MongoDB Atlas, you can use the MongoDB Search compound Operator operator filter option to match or filter documents when running $search queries. Running $match after $search is less performant than running $search with the compound Operator operator filter option.

filter 옵션에 대해 자세히 알아보려면 Atlas 설명서에서 복합 연산자를 참조하세요.

이 페이지의 예시는 sample_mflix 데이터 세트의 데이터를 사용합니다. 이 데이터 세트를 자체 관리형 MongoDB 배포서버에 로드하는 방법에 대한 자세한 내용은 샘플 데이터세트 로드를 참조하세요. 샘플 데이터베이스를 수정한 경우, 이 페이지의 예시를 실행하려면 데이터베이스를 제거하고 다시 생성해야 할 수 있습니다.

The following operation uses $match to perform an equality match on the rated field. The runtime filter limits the result to a small, representative set:

db.movies.aggregate(
[ { $match : { rated : "TV-PG", runtime : { $gt: 1000 } } } ]
)

The $match selects the documents where the rated field equals "TV-PG" and runtime is greater than 1000.

The following example selects documents to process using the $match pipeline operator and then pipes the results to the $group pipeline operator to compute a count of the documents:

db.movies.aggregate( [
{ $match: { $or: [
{ runtime: { $gt: 1000 } },
{ year: { $lt: 1910 } }
] } },
{ $group: { _id: null, count: { $sum: 1 } } }
] )
[ { _id: null, count: 6 } ]

In the aggregation pipeline, $match selects the documents where either the runtime is greater than 1000 or the year is earlier than 1910. These documents are then sent to the $group to perform a count.

배열 필드 의 요소를 기반으로 문서를 필터하다 하려면 $match 단계의 쿼리 술어에서 $elemMatch 연산자 사용합니다.

db.aggregate( [
{
$documents: [
{ student_id: 1, scores: [ 0.75, 0.65, 0.73 ] },
{ student_id: 2, scores: [ 0.9, 0.88, 0.98 ] },
{ student_id: 3, scores: [ 0.9, 0.84, 0.93 ] }
]
}, {
$match: {
scores: { $elemMatch: { $gte: 0.9 } }
}
}
] )
[
{ student_id: 2, scores: [ 0.9, 0.88, 0.98 ] },
{ student_id: 3, scores: [ 0.9, 0.84, 0.93 ] }
]

집계에 대한 자세한 정보와 사용 사례는 완전한 집계 파이프라인 튜토리얼을 참조하세요.