-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ceil.txt
82 lines (55 loc) · 1.63 KB
/
ceil.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
===================
$ceil (aggregation)
===================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. expression:: $ceil
.. versionadded:: 3.2
Returns the smallest integer greater than or equal to the specified
number.
:expression:`$ceil` has the following syntax:
.. code-block:: javascript
{ $ceil: <number> }
The ``<number>`` expression can be any valid :ref:`expression
<aggregation-expressions>` as long as it resolves to a number. For
more information on expressions, see :ref:`aggregation-expressions`.
Behavior
--------
.. include:: /includes/extracts/agg-expression-null-operand-ceil.rst
.. list-table::
:header-rows: 1
:widths: 85 15
* - Example
- Results
* - ``{ $ceil: 1 }``
- ``1``
* - ``{ $ceil: 7.80 }``
- ``8``
* - ``{ $ceil: -2.8 }``
- ``-2``
Example
-------
A collection named ``samples`` contains the following documents:
.. code-block:: javascript
{ _id: 1, value: 9.25 }
{ _id: 2, value: 8.73 }
{ _id: 3, value: 4.32 }
{ _id: 4, value: -5.34 }
The following example returns both the original value and the ceiling
value:
.. code-block:: javascript
db.samples.aggregate([
{ $project: { value: 1, ceilingValue: { $ceil: "$value" } } }
])
The operation returns the following results:
.. code-block:: javascript
{ "_id" : 1, "value" : 9.25, "ceilingValue" : 10 }
{ "_id" : 2, "value" : 8.73, "ceilingValue" : 9 }
{ "_id" : 3, "value" : 4.32, "ceilingValue" : 5 }
{ "_id" : 4, "value" : -5.34, "ceilingValue" : -5 }