$lte - Amazon DocumentDB

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

$lte

$lte 집계 연산자는 두 값을 비교하고 첫 번째 값이 두 번째 값보다 작거나 같true으면를 반환하고, 그렇지 않으면를 반환합니다false.

파라미터

  • expression1: 비교할 첫 번째 값입니다.

  • expression2: 비교할 두 번째 값입니다.

예제(MongoDB 쉘)

다음 예제에서는 $lte 연산자를 사용하여 예산 친화적인 항목을 식별하는 방법을 보여줍니다.

샘플 문서 생성

db.menu.insertMany([ { _id: 1, dish: "Salad", price: 8 }, { _id: 2, dish: "Pasta", price: 12 }, { _id: 3, dish: "Soup", price: 6 } ]);

쿼리 예제

db.menu.aggregate([ { $project: { dish: 1, price: 1, affordable: { $lte: ["$price", 10] } } } ]);

출력

[ { _id: 1, dish: 'Salad', price: 8, affordable: true }, { _id: 2, dish: 'Pasta', price: 12, affordable: false }, { _id: 3, dish: 'Soup', price: 6, affordable: true } ]

코드 예제

$lte 집계 연산자 사용에 대한 코드 예제를 보려면 사용하려는 언어의 탭을 선택합니다.

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('menu'); const result = await collection.aggregate([ { $project: { dish: 1, price: 1, affordable: { $lte: ["$price", 10] } } } ]).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['menu'] result = list(collection.aggregate([ { '$project': { 'dish': 1, 'price': 1, 'affordable': { '$lte': ['$price', 10] } } } ])) print(result) client.close() example()