@@ -47,119 +47,125 @@ Behavior
4747Examples
4848--------
4949
50- Bitwise AND
51- ~~~~~~~~~~~
52-
53- Consider the following document inserted into the collection
54- ``switches``:
50+ The following examples use the ``switches`` collection:
5551
5652.. code-block:: javascript
5753
58- { _id: 1, expdata: NumberInt(13) }
54+ db.switches.insertMany( [
55+ { _id: 1, expdata: Int32(13) },
56+ { _id: 2, expdata: Int32(3) },
57+ { _id: 3, expdata: Int32(1) }
58+ ] )
59+
60+ Bitwise AND
61+ ~~~~~~~~~~~
5962
60- The following :method:`~db.collection.update()` operation updates the
61- ``expdata`` field to the result of a bitwise ``and`` operation between
62- the current value ``NumberInt(13)`` (i.e. ``1101``) and
63- ``NumberInt(10)`` (i.e. ``1010``):
63+ Use a bitwise ``and`` in the :method:`~db.collection.updateOne()`
64+ operation to update ``expdata``.
6465
6566.. code-block:: javascript
6667
67- db.switches.update (
68+ db.switches.updateOne (
6869 { _id: 1 },
69- { $bit: { expdata: { and: NumberInt(10 ) } } }
70+ { $bit: { expdata: { and: Int32( 10 ) } } }
7071 )
7172
72- The bitwise ``and`` operation results in the integer 8 (i.e. ``1000``) :
73+ The bitwise ``and`` operation:
7374
74- .. code-block:: none
75+ - gets the bitwise value of ``expdata``
76+ - uses ``and`` to apply the bitwise value of Int32(10)
77+ - updates ``expdata`` with the result, 1000
7578
76- 1101
77- 1010
79+ .. code-block:: javascript
80+ :copyable: false
81+
82+ 1101 // expdata
83+ 1010 // Int32(10)
7884 ----
7985 1000
8086
81- And the updated document has the following value for ``expdata``:
87+ Binary 1000 is equivalent to Int32(8). The
88+ ``db.switches.find( { _id: 1 } )`` command returns the following
89+ document:
8290
8391.. code-block:: javascript
8492
8593 { "_id" : 1, "expdata" : 8 }
8694
87- :binary:`~bin.mongosh` displays ``NumberInt(8)`` as ``8``.
8895
8996Bitwise OR
9097~~~~~~~~~~
9198
92- Consider the following document inserted into the collection
93- ``switches``:
94-
95- .. code-block:: javascript
96-
97- { _id: 2, expdata: NumberLong(3) }
98-
99- The following :method:`~db.collection.update()` operation updates the
100- ``expdata`` field to the result of a bitwise ``or`` operation between
101- the current value ``NumberLong(3)`` (i.e. ``0011``) and
102- ``NumberInt(5)`` (i.e. ``0101``):
99+ Use a bitwise ``or`` in the :method:`~db.collection.updateOne()`
100+ operation to update ``expdata``.
103101
104102.. code-block:: javascript
105103
106- db.switches.update (
104+ db.switches.updateOne (
107105 { _id: 2 },
108- { $bit: { expdata: { or: NumberInt(5 ) } } }
106+ { $bit: { expdata: { or: Int32( 5 ) } } }
109107 )
110108
111- The bitwise ``or`` operation results in the integer 7 (i.e. ``0111``):
109+ The bitwise ``or`` operation:
110+
111+ - gets the bitwise value of ``expdata``
112+ - uses ``or`` to apply the bitwise value of Int32(5)
113+ - updates ``expdata`` with the result, 0111
112114
113- .. code-block:: none
115+ .. code-block:: javascript
116+ :copyable: false
114117
115- 0011
116- 0101
118+ 0111 // expdata
119+ 0101 // Int32(5)
117120 ----
118121 0111
119122
120- And the updated document has the following value for ``expdata``:
123+ Binary 0111 is equivalent to Int32(7). The
124+ ``db.switches.find( { _id: 2 } )`` command returns the following
125+ document:
121126
122127.. code-block:: javascript
123128
124- { "_id" : 2, "expdata" : NumberLong(7) }
129+ { "_id" : 2, "expdata" : 7 }
130+
125131
126132Bitwise XOR
127133~~~~~~~~~~~
128134
129- Consider the following document in the collection ``switches``:
135+ Use a bitwise ``xor`` in the :method:`~db.collection.updateOne()`
136+ operation to update ``expdata``.
130137
131138.. code-block:: javascript
132139
133- { _id: 3, expdata: NumberLong(1) }
134-
135- The following :method:`~db.collection.update()` operation updates the
136- ``expdata`` field to the result of a bitwise ``xor`` operation between
137- the current value ``NumberLong(1)`` (i.e. ``0001``) and
138- ``NumberInt(5)`` (i.e. ``0101``):
139-
140- .. code-block:: javascript
141-
142- db.switches.update(
140+ db.switches.updateOne(
143141 { _id: 3 },
144- { $bit: { expdata: { xor: NumberInt(5 ) } } }
142+ { $bit: { expdata: { xor: Int32( 5 ) } } }
145143 )
146144
147- The bitwise ``xor `` operation results in the integer 4 :
145+ The bitwise ``and `` operation:
148146
149- .. code-block:: none
147+ - gets the bitwise value of ``expdata``
148+ - uses ``and`` to apply the bitwise value of Int32(5)
149+ - updates ``expdata`` with the result, 0100
150150
151- 0001
152- 0101
151+ .. code-block:: javascript
152+ :copyable: false
153+
154+ 0001 // expdata
155+ 0101 // Int32(5)
153156 ----
154157 0100
155158
156- And the updated document has the following value for ``expdata``:
159+ Binary 0100 is equivalent to ``Int32(4)``. The
160+ ``db.switches.find( { _id: 3 } )`` command returns the following
161+ document:
157162
158163.. code-block:: javascript
159164
160- { "_id" : 3 , "expdata" : NumberLong(4) }
165+ { "_id" : 1 , "expdata" : 4 }
161166
162167.. seealso::
163168
164- - :method:`db.collection.update ()`
169+ - :method:`db.collection.updateOne ()`
165170 - :method:`db.collection.findAndModify()`
171+
0 commit comments