Skip to content

Commit d4f08fc

Browse files
authored
DOCSP-29682 bitNot Aggregation Operator (#3148) (#3192)
* DOCSP-29682 bitNot Aggregation Operator * add to toc and aggregation page * build errors * copy cleanup * DC feedback * additional feedback
1 parent 6ba0f66 commit d4f08fc

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

source/meta/aggregation-quick-reference.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ Index of Expression Operators
356356
- :group:`$avg`
357357
- :expression:`$binarySize`
358358
- :expression:`$bitAnd`
359+
- :expression:`$bitNot`
359360
- :expression:`$bitOr`
360361
- :expression:`$bsonSize`
361362
- :expression:`$ceil`

source/reference/operator/aggregation.txt

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

275275
.. versionadded:: 6.3
276276

277+
* - :expression:`$bitNot`
278+
279+
- Returns the result of a bitwise ``not`` operation on a single argument
280+
or an array that contains a single ``int`` or ``long`` value.
281+
282+
.. versionadded:: 6.3
283+
277284
* - :expression:`$bitOr`
278285

279286
- Returns the result of a bitwise ``or`` operation on an array of ``int``
@@ -1293,6 +1300,7 @@ Alphabetical Listing of Expression Operators
12931300
/reference/operator/aggregation/avg
12941301
/reference/operator/aggregation/binarySize
12951302
/reference/operator/aggregation/bitAnd
1303+
/reference/operator/aggregation/bitNot
12961304
/reference/operator/aggregation/bitOr
12971305
/reference/operator/aggregation/bottom
12981306
/reference/operator/aggregation/bottomN
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
=====================
2+
$bitNot (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:: $bitNot
19+
20+
Returns the result of a bitwise ``not`` operation on a single ``int`` or
21+
``long`` value.
22+
23+
Syntax
24+
------
25+
26+
The ``$bitNot`` operator has the following syntax:
27+
28+
.. code-block:: javascript
29+
30+
{ $bitNot: <expression> }
31+
32+
The expression can be a single argument or an array with one ``int`` or ``long``
33+
element.
34+
35+
Behavior
36+
--------
37+
38+
.. include:: /includes/fact-mongosh-integer-long-constructors.rst
39+
40+
.. include:: /includes/fact-bitwise-type-error.rst
41+
42+
If the expression evalutates to ``null``, the operation returns ``null``.
43+
44+
Example
45+
--------
46+
47+
The example on this page uses the ``switches`` collection:
48+
49+
.. code-block:: javascript
50+
51+
db.switches.insertMany( [
52+
{ _id: 0, a: NumberInt(0), b: NumberInt(127) },
53+
{ _id: 1, a: NumberInt(2), b: NumberInt(3) },
54+
{ _id: 2, a: NumberInt(3), b: NumberInt(5) }
55+
] )
56+
57+
The following aggregation uses the ``$bitNot`` operator in the
58+
:pipeline:`$project` stage:
59+
60+
.. code-block:: javascript
61+
62+
db.switches.aggregate( [
63+
{
64+
$project: {
65+
result: {
66+
$bitNot: "$a"
67+
}
68+
}
69+
}
70+
])
71+
72+
The operation returns the following results:
73+
74+
.. code-block:: javascript
75+
:copyable: false
76+
77+
[
78+
{ _id: 0, result: -1 },
79+
{ _id: 1, result: -3 },
80+
{ _id: 2, result: -4 }
81+
]
82+
83+
Learn More
84+
----------
85+
86+
- :ref:`aggregation-pipeline-operators`
87+
88+
- :ref:`update-bit`

0 commit comments

Comments
 (0)