- Reference >
- Operators >
- Aggregation Pipeline Operators >
- $floor (aggregation)
$floor (aggregation)¶
On this page
Definition¶
-
$floor
¶ New in version 3.2.
Returns the largest integer less than or equal to the specified number.
$floor
has the following syntax:The
<number>
expression can be any valid expression as long as it resolves to a number. For more information on expressions, see Expressions.
Behavior¶
If the argument resolves to a value of null
or refers to a field that is
missing, $floor
returns null
. If the argument resolves to
NaN
, $floor
returns NaN
.
Example | Results |
---|---|
{ $floor: 1 } |
1 |
{ $floor: 7.80 } |
7 |
{ $floor: -2.8 } |
-3 |
Example¶
A collection named samples
contains the following documents:
The following example returns both the original value and the floor value:
The operation returns the following results: