정의
호환성
다음 환경에서 호스팅되는 배포에 $gt 사용할 수 있습니다.
MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
구문
$gt 연산자 형식은 다음과 같습니다.
{ field: { $gt: value } }
예시
이 페이지의 예제에서는 sample_mflix 샘플 데이터 세트 의 데이터를 사용합니다. 이 데이터 세트를 자체 관리형 MongoDB deployment 에 로드하는 방법에 대한 자세한 내용은 샘플 데이터 세트 로드를 참조하세요. 샘플 데이터베이스를 수정한 경우 이 페이지의 예제를 실행 하려면 데이터베이스를 삭제하고 다시 만들어야 할 수 있습니다.
문서 필드 일치
이 예시 에서는 runtime 이 1000 분보다 큰 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이라는 내장된 문서 와 일치합니다. 이 작업은 rating 가 9.5보다 큰 문서에서 { highestRated: true } 를 설정합니다.
db.movies.updateMany( { "imdb.rating" : { $gt: 9.5 } }, { $set: { "highestRated": true } } )
{ acknowledged: true, insertedId: null, matchedCount: 1, modifiedCount: 1, upsertedCount: 0 }