기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
$lte
Amazon DocumentDB의 $lte 연산자는 지정된 필드의 값이 지정된 값보다 작거나 같은 문서를 일치시키는 데 사용됩니다. 이 연산자는 수치 비교를 기반으로 데이터를 필터링하고 쿼리하는 데 유용합니다.
파라미터
-
field: 비교할 필드입니다.
-
value: 비교할 값입니다.
예제(MongoDB 쉘)
다음 예제에서는 연$lte산자를 사용하여 quantity 필드가 10 이하인 문서를 검색하는 방법을 보여줍니다.
샘플 문서 생성
db.inventory.insertMany([
{ item: "canvas", qty: 100 },
{ item: "paint", qty: 50 },
{ item: "brush", qty: 10 },
{ item: "paper", qty: 5 }
]);
쿼리 예제
db.inventory.find({ qty: { $lte: 10 } });
출력
{ "_id" : ObjectId("..."), "item" : "brush", "qty" : 10 },
{ "_id" : ObjectId("..."), "item" : "paper", "qty" : 5 }
코드 예제
$lte 명령을 사용하기 위한 코드 예제를 보려면 사용하려는 언어의 탭을 선택합니다.
- Node.js
-
const { MongoClient } = require("mongodb");
async function main() {
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("inventory");
const result = await collection.find({ qty: { $lte: 10 } }).toArray();
console.log(result);
await client.close();
}
main();
- Python
-
from pymongo import MongoClient
def main():
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["inventory"]
result = list(collection.find({ "qty": { "$lte": 10 } }))
print(result)
client.close()
if __name__ == "__main__":
main()