Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
Click here >
Docs Menu
Docs Home
/ /

$gt (쿼리 자 연산자)

$gt

$gt 필드 값이 지정된 값(>)보다 큰 문서를 선택합니다.

대부분의 데이터 유형에서 비교 연산자BSON 유형 이 쿼리 값의 유형과 일치하는 필드에 대해서만 비교를 수행합니다. MongoDB 는 타입 브라케팅을 통해 제한된 BSON 비교를 지원합니다.

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

  • MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스

$gt 연산자 형식은 다음과 같습니다.

{ field: { $gt: value } }

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

이 예시 에서는 runtime1000 분보다 큰 movies 컬렉션 에서 문서를 선택합니다.

db.movies.find(
{ runtime: { $gt: 1000 } },
{ _id: 0, title: 1, runtime: 1, plot: 1 }
)
[
{
plot: 'The economic and cultural growth of Colorado spanning two centuries from the mid-1700s to the late-1970s.',
runtime: 1256,
title: 'Centennial'
},
{
plot: 'A documentary on the history of the sport with major topics including Afro-American players, player/team owner relations and the resilience of the game.',
runtime: 1140,
title: 'Baseball'
}
]

updateMany()작업은 rating라는 하위 필드가 있는 imdb이라는 내장된 문서 와 일치합니다. 이 작업은 rating9.5보다 큰 문서에서 { highestRated: true } 를 설정합니다.

db.movies.updateMany(
{ "imdb.rating" : { $gt: 9.5 } },
{ $set: { "highestRated": true } }
)
{
acknowledged: true,
insertedId: null,
matchedCount: 1,
modifiedCount: 1,
upsertedCount: 0
}

돌아가기

$eq

이 페이지의 내용