@@ -143,35 +143,51 @@ NumberLong
143
143
144
144
By default, the :program:`mongo` shell treats all numbers as
145
145
floating-point values. The :program:`mongo` shell provides the
146
- ``NumberLong()`` class to handle numbers of 64-bit integers.
146
+ ``NumberLong()`` class to handle 64-bit integers.
147
147
148
148
The ``NumberLong()`` constructor accepts the long as a string:
149
149
150
150
.. code-block:: javascript
151
151
152
- NumberLong("20908458868526654 ")
152
+ NumberLong("2090845886852 ")
153
153
154
154
The following examples use the ``NumberLong()`` class to write to the
155
155
collection:
156
156
157
157
.. code-block:: javascript
158
158
159
- db.collection.insert( { _id: 10, calc: NumberLong("20908458868526654 ") } )
159
+ db.collection.insert( { _id: 10, calc: NumberLong("2090845886852 ") } )
160
160
db.collection.update( { _id: 10 },
161
- { $set: { calc: NumberLong("209084588685266550") } } )
161
+ { $set: { calc: NumberLong("2555555000000") } } )
162
+ db.collection.update( { _id: 10 },
163
+ { $inc: { calc: NumberLong(5) } } )
164
+
165
+ Retrieve the document to verify:
166
+
167
+ .. code-block:: javascript
168
+
169
+ db.collection.findOne( { _id: 10 } )
170
+
171
+ In the returned document, the ``calc`` field contains a
172
+ ``NumberLong`` object:
173
+
174
+ .. code-block:: sh
175
+
176
+ { "_id" : 10, "calc" : NumberLong("2555555000005") }
162
177
163
178
If you :operator:`increment <$inc>` the field that contains a
164
- ``NumberLong`` object, the data type changes to a floating point value,
165
- as in the following example:
179
+ ``NumberLong`` object by a **float** , the data type changes to a
180
+ floating point value, as in the following example:
166
181
167
- #. :operator:`Increment <$inc>` the ``calc`` field:
182
+ #. :operator:`Increment <$inc>` the ``calc`` field by ``5`` which the
183
+ :program:`mongo` shell treats as a float:
168
184
169
185
.. code-block:: javascript
170
186
171
187
db.collection.update( { _id: 10 },
172
188
{ $inc: { calc: 5 } } )
173
189
174
- #. Select the updated document:
190
+ #. Retrieve the updated document:
175
191
176
192
.. code-block:: javascript
177
193
@@ -182,4 +198,4 @@ as in the following example:
182
198
183
199
.. code-block:: sh
184
200
185
- { "_id" : 10, "calc" : 209084588685266560 }
201
+ { "_id" : 10, "calc" : 2555555000010 }
0 commit comments