Docs Menu
Docs Home
/
データベース マニュアル
/ / /

$ne(集計)

$ne

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

  • true 、値が等しくない場合。

  • false 値が等しい場合。

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

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

{ $ne: [ <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 }
] )

次の操作では、$ne 演算子を使用して、qty250 と等しくないかどうかを判定します。

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

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

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

戻る

$multiply

項目一覧