Docs Menu
Docs Home
/
MongoDB マニュアル
/ / /

$lte(集計)

項目一覧

  • 定義
$lte

2 つの値を比較し、以下を返します。

  • true 1 番目の値が 2 番目の値より小さいか等しいとき

  • false 1 番目の値が 2 番目の値より大きいとき

$lteは、異なる型の値に対して指定された BSON 比較順序を使用して、値と型の両方を比較します。

$lte の構文は次のとおりです。

{ $lte: [ <expression1>, <expression2> ] }

式の詳細については、「式 」を参照してください。

以下のドキュメントを持つinventoryコレクションを検討してください。

db.inventory.insertMany( [
{ _id : 1, item : "abc1", description: "product 1", qty: 300 },
{ _id : 2, item : "abc2", description: "product 2", qty: 200 },
{ _id : 3, item : "xyz1", description: "product 3", qty: 250 },
{ _id : 4, item : "VWZ1", description: "product 4", qty: 300 },
{ _id : 5, item : "VWZ2", description: "product 5", qty: 180 }
] )

次の操作では、 $lte演算子を使用して、 qty250以下であるかどうかを判断します。

db.inventory.aggregate(
[
{
$project:
{
item: 1,
qty: 1,
qtyLte250: { $lte: [ "$qty", 250 ] },
_id: 0
}
}
]
)

この操作は次の結果を返します。

{ "item" : "abc1", "qty" : 300, "qtyLte250" : false }
{ "item" : "abc2", "qty" : 200, "qtyLte250" : true }
{ "item" : "xyz1", "qty" : 250, "qtyLte250" : true }
{ "item" : "VWZ1", "qty" : 300, "qtyLte250" : false }
{ "item" : "VWZ2", "qty" : 180, "qtyLte250" : true }

戻る

$lt

項目一覧