$bitNot
The `$bitNot` operator performs a bitwise NOT operation on integer values. It inverts all the bits of the operand, turning 1s into 0s and 0s into 1s. The result is the bitwise complement of the input value.
Syntax
{
$bitNot: <expression>
}
Parameters
expression
numberrequiredAn expression that evaluates to an integer. The $bitNot operator performs a bitwise NOT operation on this value.
Examples
Sample Data
{
"_id": "0fcc0bf0-ed18-4ab8-b558-9848e18058f4",
"name": "First Up Consultants | Beverage Shop",
"staff": {
"totalStaff": {
"fullTime": 8,
"partTime": 20
}
}
}
Basic bitwise NOT operation
Performs bitwise NOT on the number of full-time staff members.
Query:
db.stores.aggregate([
{ $match: { _id: "40d6f4d7-50cd-4929-9a07-0a7a133c2e74" } },
{
$project: {
name: 1,
fullTimeStaff: "$staff.totalStaff.fullTime",
bitwiseComplement: { $bitNot: "$staff.totalStaff.fullTime" }
}
}
])
Output:
[
{
"_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
"name": "Proseware, Inc. | Home Entertainment Hub",
"fullTimeStaff": 19,
"bitwiseComplement": -20
}
]