$gt - Amazon DocumentDB

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

$gt

Amazon DocumentDB의 $gt 연산자는 지정된 필드의 값이 지정된 값보다 큰 문서를 선택하는 데 사용됩니다. 이 연산자는 수치 비교를 기반으로 데이터를 필터링하고 쿼리하는 데 유용합니다.

파라미터

  • field: 비교할 필드입니다.

  • value: 비교할 값입니다.

예제(MongoDB 쉘)

다음 예제에서는 $gt 연산자를 사용하여 age 필드가 30보다 큰 모든 문서를 찾는 방법을 보여줍니다.

샘플 문서 생성

db.users.insertMany([ { name: "John", age: 25 }, { name: "Jane", age: 32 }, { name: "Bob", age: 45 }, { name: "Alice", age: 28 } ]);

쿼리 예제

db.users.find({ age: { $gt: 30 } });

출력

{ "_id" : ObjectId("6249e5c22a5d39884a0a0001"), "name" : "Jane", "age" : 32 }, { "_id" : ObjectId("6249e5c22a5d39884a0a0002"), "name" : "Bob", "age" : 45 }

코드 예제

$gt 명령을 사용하기 위한 코드 예제를 보려면 사용하려는 언어의 탭을 선택합니다.

Node.js
const { MongoClient } = require('mongodb'); async function findUsersOlderThan30() { const client = await MongoClient.connect('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false'); const db = client.db('test'); const users = await db.collection('users').find({ age: { $gt: 30 } }).toArray(); console.log(users); await client.close(); } findUsersOlderThan30();
Python
from pymongo import MongoClient def find_users_older_than_30(): client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') db = client.test users = list(db.users.find({ 'age': { '$gt': 30 } })) print(users) client.close() find_users_older_than_30()