$lte - Amazon DocumentDB

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

$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()