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

$gte(쿼리 자 연산자)

$gte

$gte 지정된 필드 의 값이 지정된 값보다 크거나 같은(>=) 문서를 선택합니다.

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

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

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

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

{ field: { $gte: value } }

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

이 예시 runtime720 분 이상인 movies 컬렉션 의 문서를 선택합니다.

db.movies.find(
{ "runtime": { $gte: 720 } },
{ _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 dramatization of the missions and adventures of the greatest spy in British history.',
runtime: 720,
title: 'Reilly: Ace of Spies'
},
{
plot: "A 13-hour mini-series detailing James A. Michner's fictional account of the American space program from the years after World War II to the Apollo landings on the moon in the early 1970's.",
runtime: 780,
title: 'Space'
},
{
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'
},
{
plot: 'Taken spans five decades and four generations, centering on three families: the Keys, Crawfords, and Clarkes. World War II veteran Russell Keys is plagued by nightmares of his abduction by ...',
runtime: 877,
title: 'Taken'
}
]

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

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

9.5보다 큰 imdb.rating가 있는 첫 번째 문서에서만 higestRated 필드를 설정하려면 updateOne()를 사용합니다.

돌아가기

$gt

이 페이지의 내용