$bitNot (聚合)
定义
新在版本6.3.
语法
$bitNot
操作符的语法如下
{ $bitNot: <expression> }
表达式可以是一个单一参数或一个包含一个 int
或 long
元素的数组。
行为
注意
如果数组中的任何参数是字符串、双精度浮点数或十进制数等其他数据类型,MongoDB 将返回错误。
如果表达式评估结果为 null
,则操作返回 null
。
示例
本页面上的示例使用了 switches
集合
db.switches.insertMany( [ { _id: 0, a: NumberInt(0), b: NumberInt(127) }, { _id: 1, a: NumberInt(2), b: NumberInt(3) }, { _id: 2, a: NumberInt(3), b: NumberInt(5) } ] )
以下聚合操作使用了 $bitNot
操作符在$project
阶段
db.switches.aggregate( [ { $project: { result: { $bitNot: "$a" } } } ])
操作返回以下结果
[ { _id: 0, result: -1 }, { _id: 1, result: -3 }, { _id: 2, result: -4 } ]