Skip to content

Commit 83d5cdc

Browse files
committed
DOCS-4568: updates to extended json page
- clarifies that you need quotes around NumberLong values or risk loosing accuracy (numbers can become negative) - updates undefined to clarify that it cannot be used in a query except by searching using the $type operator
1 parent aff8c00 commit 83d5cdc

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

source/reference/mongodb-extended-json.txt

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,30 @@ Undefined Type
294294

295295
The representation for the JavaScript/BSON undefined type.
296296

297+
You *cannot* use ``undefined`` in query documents.
298+
Consider the following document inserted into the ``people`` collection:
299+
300+
.. code-block:: sh
301+
302+
db.people.insert( { name : Sally, age : undefined } )
303+
304+
The following queries return an error:
305+
306+
.. code-block:: sh
307+
308+
db.people.find( { age : undefined } )
309+
db.people.find( { age : ( $gte : undefined ) } )
310+
311+
However, you can query for undefined values using :query:`$type`, as
312+
in:
313+
314+
.. code-block:: sh
315+
316+
db.people.find( { age : { $type : 6 } } )
317+
318+
This query returns all documents for which the ``age`` field has
319+
value ``undefined``.
320+
297321
MinKey
298322
~~~~~~
299323

@@ -379,6 +403,25 @@ NumberLong
379403

380404
- .. code-block:: none
381405

382-
NumberLong( <number> )
406+
NumberLong( "<number>" )
407+
408+
``NumberLong`` is a 64 bit signed integer. You must include quotation
409+
marks or it will be interpreted as a floating point number, resulting
410+
in a loss of accuracy.
411+
412+
For example, the following commands insert ``9223372036854775807`` as a
413+
``NumberLong`` with and without quotation marks around the integer value:
414+
415+
.. code-block:: sh
416+
417+
db.json.insert( { longQuoted : NumberLong("9223372036854775807") } )
418+
db.json.insert( { longUnQuoted : NumberLong(9223372036854775807) } )
419+
420+
When you retrieve the documents, the value of ``longUnquoted`` has
421+
changed, while ``longQuoted`` retains its accuracy:
422+
423+
.. code-block:: sh
383424

384-
Number long is a 64 bit signed integer.
425+
db.json.find()
426+
{ "_id" : ObjectId("54ee1f2d33335326d70987df"), "longQuoted" : NumberLong("9223372036854775807") }
427+
{ "_id" : ObjectId("54ee1f7433335326d70987e0"), "longUnquoted" : NumberLong("-9223372036854775808") }

0 commit comments

Comments
 (0)