AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

$bitNot(式演算子)

バージョン6.3の新機能。

$bitNot

単一のintまたはlong値に対するビット単位のnot演算の結果を返します。

$bitNot演算子の構文は次のとおりです。

{ $bitNot: <expression> }

式は、単一の引数、または 1 つのint 要素またはlong 要素を含む配列にすることができます。

注意

All numbers in mongosh are doubles, not integers. To specify integers in mongosh, use the Int32() or the Long() constructor. To learn more, see Int32 or Long.

MongoDBドライバーが数値を処理する方法については、 ドライバーのドキュメント を参照してください。

配列内のいずれかの引数がstring、double、decimal など、異なるデータ型である場合、MongoDB はエラーを返します。

式がnullと評価された場合、操作はnullを返します。

このページの例では、 switchesコレクションを使用しています。

db.switches.insertMany( [
{ _id: 0, a: Int32(0), b: Int32(127) },
{ _id: 1, a: Int32(2), b: Int32(3) },
{ _id: 2, a: Int32(3), b: Int32(5) }
] )

次の集計では、 $projectステージで$bitNot演算子が使用されています。

db.switches.aggregate( [
{
$project: {
result: {
$bitNot: "$a"
}
}
}
])

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

[
{ _id: 0, result: -1 },
{ _id: 1, result: -3 },
{ _id: 2, result: -4 }
]
このページを評価