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

$not(集計)

項目一覧

  • 定義
  • 動作
$not

ブール値を評価し、逆のブール値を返します。つまり、 trueと評価される式が渡された場合、 $notfalseを返します。 falseと評価される式が渡された場合、 $nottrueを返します。

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

{ $not: [ <expression> ] }

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

falseブール値に加えて、 $notは、次のnull0undefined値をfalseとして評価します。 $notは、ゼロ以外の数値と配列を含む他のすべての値をtrueとして評価します。

結果
{ $not: [ true ] }
false
{ $not: [ [ false ] ] }
false
{ $not: [ false ] }
true
{ $not: [ null ] }
true
{ $not: [ 0 ] }
true

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

{ "_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 }

次の操作では、 $not演算子を使用して、 qty250より大きくないかどうかを判断します。

db.inventory.aggregate(
[
{
$project:
{
item: 1,
result: { $not: [ { $gt: [ "$qty", 250 ] } ] }
}
}
]
)

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

{ "_id" : 1, "item" : "abc1", "result" : false }
{ "_id" : 2, "item" : "abc2", "result" : true }
{ "_id" : 3, "item" : "xyz1", "result" : true }
{ "_id" : 4, "item" : "VWZ1", "result" : false }
{ "_id" : 5, "item" : "VWZ2", "result" : true }

戻る

$ne

項目一覧