Skip to content

Commit 2fdfd0b

Browse files
authored
DOCSP-44585-double-type (#362)
* DOCSP-44585-double-type * * * external review
1 parent ae0afb5 commit 2fdfd0b

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

source/reference/data-types.txt

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,34 @@ Starting in 1.8.0, the ``ObjectId`` wrapper no longer accepts:
6060

6161
:method:`ObjectId`
6262

63+
Double
64+
------
65+
66+
The :node-api:`Double() <Double.html>` constructor can be used to
67+
explicitly specify a double:
68+
69+
.. code-block:: javascript
70+
71+
db.types.insertOne(
72+
{
73+
"_id": 2,
74+
"value": Double(1),
75+
"expectedType": "Double"
76+
}
77+
)
78+
79+
.. note::
80+
81+
If field's value is a number that can be converted to a 32-bit integer,
82+
``mongosh`` will store it as ``Int32``. If not, ``mongosh`` defaults to
83+
storing the number as a ``Double``. To specify the value type, use the
84+
``Double()`` or ``Int32()`` constructors.
85+
6386
.. _shell-type-int:
6487

6588
Int32
6689
-----
6790

68-
If a number can be converted to a 32-bit integer, ``mongosh`` will
69-
store it as ``Int32``. If not, ``mongosh`` defaults to storing the
70-
number as a ``Double``. Numerical values that are stored as ``Int32``
71-
in ``mongosh`` would have been stored by default as ``Double`` in the
72-
``mongo`` shell.
73-
7491
The :node-api:`Int32() <Int32.html>` constructor can be used to
7592
explicitly specify 32-bit integers.
7693

@@ -79,7 +96,7 @@ explicitly specify 32-bit integers.
7996
db.types.insertOne(
8097
{
8198
"_id": 1,
82-
"value": Int32("1"),
99+
"value": Int32(1),
83100
"expectedType": "Int32"
84101
}
85102
)
@@ -103,7 +120,7 @@ explicitly specify a 64-bit integer.
103120
db.types.insertOne(
104121
{
105122
"_id": 3,
106-
"value": Long("1"),
123+
"value": Long(1),
107124
"expectedType": "Long"
108125
}
109126
)

0 commit comments

Comments
 (0)