@@ -17,7 +17,7 @@ Definition
17
17
18
18
.. versionadded:: 4.4
19
19
20
- :expression:` $isNumber` checks if the specified
20
+ `` $isNumber` ` checks if the specified
21
21
:ref:`expression <aggregation-expressions>` resolves to one of the
22
22
following numeric :term:`BSON types`:
23
23
@@ -26,16 +26,15 @@ Definition
26
26
- :bsontype:`Double <Double>`
27
27
- :bsontype:`Long <Int64>`
28
28
29
- :expression:` $isNumber` returns:
29
+ `` $isNumber` ` returns:
30
30
31
31
- ``true`` if the expression resolves to a number.
32
32
33
33
- ``false`` if the expression resolves to any other
34
34
:doc:`BSON type </reference/mongodb-extended-json>`, ``null``, or
35
35
a missing field.
36
36
37
- :expression:`$isNumber` has the following
38
- :ref:`operator expression syntax
37
+ ``$isNumber`` has the following :ref:`operator expression syntax
39
38
<agg-quick-ref-operator-expressions>`:
40
39
41
40
.. code-block:: javascript
@@ -53,20 +52,20 @@ Definition
53
52
Example
54
53
-------
55
54
56
- Use :expression:` $isNumber` to Check If A Field Is Numeric
57
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
+ Use $isNumber to Check if a Field is Numeric
56
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
57
59
58
Issue the following operation against the ``examples.sensors``
60
59
collection to populate test data:
61
60
62
61
.. code-block:: javascript
63
62
64
63
db.getSiblingDB("examples").sensors.insertMany([
65
- { "_id" : 1, "reading" : NumberDecimal(26.0) }
66
- { "_id" : 2, "reading" : NumberLong(25.0) }
67
- { "_id" : 3, "reading" : NumberInt(24) }
68
- { "_id" : 4, "reading" : 24.0 }
69
- { "_id" : 5, "reading" : "24" }
64
+ { "_id" : 1, "reading" : NumberDecimal(26.0) },
65
+ { "_id" : 2, "reading" : NumberLong(25.0) },
66
+ { "_id" : 3, "reading" : NumberInt(24) },
67
+ { "_id" : 4, "reading" : 24.0 },
68
+ { "_id" : 5, "reading" : "24" },
70
69
{ "_id" : 6, "reading" : [ NumberDecimal(26) ]}
71
70
])
72
71
@@ -90,6 +89,7 @@ stage to add the following fields to each document:
90
89
The aggregation operation returns the following results:
91
90
92
91
.. code-block:: javascript
92
+ :copyable: false
93
93
94
94
{ "_id" : 1, "reading" : NumberDecimal("26.0000000000000"), "isNum " : true, "type" : "decimal" }
95
95
{ "_id" : 2, "reading" : NumberLong(25), "isNum " : true, "type" : "long" }
@@ -98,8 +98,8 @@ The aggregation operation returns the following results:
98
98
{ "_id" : 5, "reading" : "24", "isNum " : false, "type" : "string" }
99
99
{ "_id" : 6, "reading" : [ NumberDecimal("26.0000000000000") ], "isNum " : false, "type" : "array" }
100
100
101
- Conditionally Modify Fields using :expression:` $isNumber`
102
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101
+ Conditionally Modify Fields using $isNumber
102
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103
103
104
104
The ``grades`` collection contains data on student grades. The ``grade``
105
105
field may either store a string letter grade *or* a numeric point value.
@@ -136,7 +136,7 @@ field may either store a string letter grade *or* a numeric point value.
136
136
The following aggregation uses the :pipeline:`$addFields` stage to add a
137
137
``points`` field containing the numeric grade value for that course. The
138
138
stage uses the :expression:`$cond` operator to set the value of
139
- ``points`` based on the output of :expression:` $isNumber`:
139
+ ``points`` based on the output of `` $isNumber` `:
140
140
141
141
- If ``true``, ``grades`` already contains the numeric point value.
142
142
Set ``points`` equal to ``grades``.
0 commit comments