$bitXor
New from version 8.0.1.
The $bitXor operator in Amazon DocumentDB performs a bitwise XOR operation on integer or long values.
Parameters
expressions: An array of two or more expressions, which can resolve to integers or longs.
Example (MongoDB Shell)
The following example shows how to use the $bitXor operator to perform bitwise XOR on two fields.
Create sample documents
db.flags.insertMany([ {_id: 1, a: 13, b: 10}, {_id: 2, a: 7, b: 5}, {_id: 3, a: 15, b: 9} ]);
Query example
db.flags.aggregate([ { $project: { result: { $bitXor: ["$a", "$b"] } } } ]);
Output
[
{_id: 1, result: 7},
{_id: 2, result: 2},
{_id: 3, result: 6}
]
In binary: 13 (1101) XOR 10 (1010) = 7 (0111); 7 (0111) XOR 5 (0101) = 2 (0010); 15 (1111) XOR 9 (1001) = 6 (0110).
Code examples
To view a code example for using the $bitXor operator, choose the tab for the language that you want to use: