Skip to content

Commit a5abe37

Browse files
authored
DOCSP-29683 bitXor Aggregation Operator (#3193) (#3200)
* DOCSP-29683 bitXor Aggregation Operator * build errors
1 parent d4f08fc commit a5abe37

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

source/meta/aggregation-quick-reference.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ Index of Expression Operators
358358
- :expression:`$bitAnd`
359359
- :expression:`$bitNot`
360360
- :expression:`$bitOr`
361+
- :expression:`$bitXor`
361362
- :expression:`$bsonSize`
362363
- :expression:`$ceil`
363364
- :expression:`$cmp`

source/reference/operator/aggregation.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,13 @@ Alphabetical Listing of Expression Operators
288288

289289
.. versionadded:: 6.3
290290

291+
* - :expression:`$bitXor`
292+
293+
- Returns the result of a bitwise ``xor`` (exclusive or) operation on an
294+
array of ``int`` and ``long`` values.
295+
296+
.. versionadded:: 6.3
297+
291298
* - :group:`$bottom`
292299

293300
- Returns the bottom element within a group according to the specified
@@ -1302,6 +1309,7 @@ Alphabetical Listing of Expression Operators
13021309
/reference/operator/aggregation/bitAnd
13031310
/reference/operator/aggregation/bitNot
13041311
/reference/operator/aggregation/bitOr
1312+
/reference/operator/aggregation/bitXor
13051313
/reference/operator/aggregation/bottom
13061314
/reference/operator/aggregation/bottomN
13071315
/reference/operator/aggregation/bsonSize
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
=====================
2+
$bitXor (aggregation)
3+
=====================
4+
5+
.. default-domain:: mongodb
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
Definition
14+
----------
15+
16+
.. versionadded:: 6.3
17+
18+
.. expression:: $bitXor
19+
20+
Returns the result of a bitwise ``xor`` (exclusive or) operation on an
21+
array of ``int`` and ``long`` values.
22+
23+
Syntax
24+
------
25+
26+
The ``$bitXor`` operator has the following syntax:
27+
28+
.. code-block:: javascript
29+
30+
{ $bitXor: { [ <expression1>, <expression2>, ... ] }
31+
32+
Behavior
33+
--------
34+
35+
.. include:: /includes/fact-bitwise-integer-long-results.rst
36+
37+
.. include:: /includes/fact-mongosh-integer-long-constructors.rst
38+
39+
.. include:: /includes/fact-bitwise-type-error.rst
40+
41+
If the argument is an empty array, the operation returns ``NumberInt(0)``.
42+
43+
If any of the arguments in the array equate to ``null``, the operation returns
44+
``null``.
45+
46+
Example
47+
--------
48+
49+
The example on this page uses the ``switches`` collection:
50+
51+
.. code-block:: javascript
52+
53+
db.switches.insertMany( [
54+
{ _id: 0, a: NumberInt(0), b: NumberInt(127) },
55+
{ _id: 1, a: NumberInt(2), b: NumberInt(3) },
56+
{ _id: 2, a: NumberInt(3), b: NumberInt(5) }
57+
] )
58+
59+
The following aggregation uses the ``$bitXor`` operator in the
60+
:pipeline:`$project` stage:
61+
62+
.. code-block:: javascript
63+
64+
db.switches.aggregate( [
65+
{
66+
$project: {
67+
result: {
68+
$bitXor: ["$a", "$b"]
69+
}
70+
}
71+
}
72+
])
73+
74+
The operation returns the following results:
75+
76+
.. code-block:: javascript
77+
:copyable: false
78+
79+
[
80+
{ _id: 0, result: 127 },
81+
{ _id: 1, result: 1 },
82+
{ _id: 2, result: 6 }
83+
]
84+
85+
Learn More
86+
----------
87+
88+
- :ref:`aggregation-pipeline-operators`
89+
90+
- :ref:`update-bit`

0 commit comments

Comments
 (0)