$lt - Amazon DocumentDB

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

$lt

Amazon DocumentDB의 $lt 연산자는 지정된 값보다 작은 값을 일치시키는 데 사용됩니다. 이 연산자는 수치 비교를 기반으로 데이터를 필터링하고 쿼리하는 데 유용합니다.

파라미터

  • field: 확인할 필드 이름입니다.

  • value: 비교할 값입니다.

예제(MongoDB 쉘)

다음 예제에서는 $lt 연산자를 사용하여 Inventory.OnHand 값이 50 미만인 문서를 검색하는 방법을 보여줍니다.

샘플 문서 생성

db.example.insertMany([ { "_id": 1, "Inventory": { "OnHand": 25, "Sold": 60 }, "Colors": ["Red", "Blue"] }, { "_id": 2, "Inventory": { "OnHand": 75, "Sold": 40 }, "Colors": ["Red", "White"] }, { "_id": 3, "Inventory": { "OnHand": 10, "Sold": 85 }, "Colors": ["Red", "Green"] } ]);

쿼리 예제

db.example.find({ "Inventory.OnHand": { $lt: 50 } })

출력

{ "_id" : 1, "Inventory" : { "OnHand" : 25, "Sold" : 60 }, "Colors" : [ "Red", "Blue" ] } { "_id" : 3, "Inventory" : { "OnHand" : 10, "Sold" : 85 }, "Colors" : [ "Red", "Green" ] }

코드 예제

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

Node.js
const { MongoClient } = require('mongodb'); async function example() { 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 collection = db.collection('example'); const result = await collection.find({ "Inventory.OnHand": { $lt: 50 } }).toArray(); console.log(result); await client.close(); } example();
Python
from pymongo import MongoClient def example(): client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') db = client['test'] collection = db['example'] result = list(collection.find({ "Inventory.OnHand": { "$lt": 50 } })) print(result) client.close() example()