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