Skip to content

Commit 01b0b55

Browse files
authored
DOCSP-29680 bitAnd Aggregation Operator (#3082)
* DOCSP-2960 bitAnd Aggregation Operator * DOCSP-29680 bitAnd Aggregation Operator * add to TOC, aggregation operator page * update title * JA feedback * typos * JA feedback pt 2 * davis feedback * unordered lists * learn more bullets
1 parent cb359fb commit 01b0b55

File tree

5 files changed

+145
-6
lines changed

5 files changed

+145
-6
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.. note::
2+
3+
All numbers in :binary:`~bin.mongosh` are doubles, not integers. To to
4+
specify integers in :binary:`~bin.mongosh`, use the ``NumberInt()`` or the
5+
``NumberLong()`` constructor. To learn more, see :ref:`shell-type-int` or
6+
:ref:`shell-type-long`.
7+
8+
To learn how your MongoDB driver handles numeric values, refer to your
9+
:driver:`driver's documentation </>`.
10+
11+
12+

source/meta/aggregation-quick-reference.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ Index of Expression Operators
355355
- :expression:`$atanh`
356356
- :group:`$avg`
357357
- :expression:`$binarySize`
358+
- :expression:`$bitAnd`
358359
- :expression:`$bsonSize`
359360
- :expression:`$ceil`
360361
- :expression:`$cmp`

source/reference/operator/aggregation.txt

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

268268
.. versionadded:: 4.4
269269

270+
* - :expression:`$bitAnd`
271+
272+
- Returns the result of a bitwise ``and`` operation on an array of ``int``
273+
or ``long`` values.
274+
275+
.. versionadded:: 6.3
276+
270277
* - :group:`$bottom`
271278

272279
- Returns the bottom element within a group according to the specified
@@ -1278,6 +1285,7 @@ Alphabetical Listing of Expression Operators
12781285
/reference/operator/aggregation/atanh
12791286
/reference/operator/aggregation/avg
12801287
/reference/operator/aggregation/binarySize
1288+
/reference/operator/aggregation/bitAnd
12811289
/reference/operator/aggregation/bottom
12821290
/reference/operator/aggregation/bottomN
12831291
/reference/operator/aggregation/bsonSize
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
=====================
2+
$bitAnd (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:: $bitAnd
19+
20+
Returns the result of a bitwise ``and`` operation on an array of ``int`` or
21+
``long`` values.
22+
23+
Syntax
24+
------
25+
26+
The :expression:`$bitAnd` operator has the following syntax:
27+
28+
.. code-block:: javascript
29+
30+
{ $bitAnd: { [ <expression1>, <expression2>, ... ] }
31+
32+
Behavior
33+
--------
34+
35+
If the operands include both integers and long values, MongoDB sign-extends the
36+
calculated integer result and returns a long value. Otherwise, if the operands
37+
include only integers or only longs, MongoDB returns results with the
38+
corresponding value type.
39+
40+
.. include:: /includes/fact-mongosh-integer-long-constructors.rst
41+
42+
If any of the operands equate to ``null``, the operation returns ``null``.
43+
44+
Examples
45+
--------
46+
47+
The examples on this page use the ``switches`` collection, which contains the
48+
following documents:
49+
50+
.. code-block:: javascript
51+
52+
db.switches.insertMany( [
53+
{ _id: 0, a: NumberInt(0), b: NumberInt(127) },
54+
{ _id: 1, a: NumberInt(2), b: NumberInt(3) },
55+
{ _id: 2, a: NumberInt(3), b: NumberInt(5) }
56+
] )
57+
58+
Bitwise ``AND`` with Two Integers
59+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60+
61+
The following aggregation uses the :expression:`$bitAnd` operator in the
62+
:pipeline:`$project` stage:
63+
64+
.. code-block:: javascript
65+
66+
db.switches.aggregate( [
67+
{
68+
$project: {
69+
result: {
70+
$bitAnd: [ "$a", "$b" ]
71+
}
72+
}
73+
}
74+
])
75+
76+
The operation returns the following results:
77+
78+
.. code-block:: javascript
79+
:copyable: false
80+
81+
[
82+
{ _id: 0, result: 0 }
83+
{ _id: 1, result: 2 }
84+
{ _id: 2, result: 1 }
85+
]
86+
87+
Bitwise ``AND`` with a Long and Integer
88+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89+
90+
The following aggregation uses the :expression:`$bitAnd` operator in the
91+
:pipeline:`$project` stage:
92+
93+
.. code-block:: javascript
94+
95+
db.switches.aggregate( [
96+
{
97+
$project: {
98+
result: {
99+
$bitAnd: [ "$a", NumberLong("63") ]
100+
}
101+
}
102+
}
103+
])
104+
105+
The operation returns the following results:
106+
107+
.. code-block:: javascript
108+
:copyable: false
109+
110+
[
111+
{ _id: 0, result: Long("0") }
112+
{ _id: 1, result: Long("2") }
113+
{ _id: 2, result: Long("3") }
114+
]
115+
116+
Learn More
117+
----------
118+
119+
- :ref:`aggregation-pipeline-operators`
120+
121+
- :ref:`update-bit`

source/reference/operator/update/bit.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _update-bit:
2+
13
====
24
$bit
35
====
@@ -30,12 +32,7 @@ Definition
3032

3133
.. include:: /includes/use-dot-notation.rst
3234

33-
.. note::
34-
35-
All numbers in :binary:`~bin.mongosh` are doubles, not
36-
integers. Use the ``NumberInt()`` or the ``NumberLong()``
37-
constructor to specify integers. See :ref:`shell-type-int` or
38-
:ref:`shell-type-long` for more information.
35+
.. include:: /includes/fact-mongosh-integer-long-constructors.rst
3936

4037
Behavior
4138
--------

0 commit comments

Comments
 (0)