$ceil
New from version 4.0
The $ceil operator in Amazon DocumentDB, as in MongoDB, rounds a number up to the nearest integer. This is useful when you need to perform mathematical operations on numeric fields and ensure the result is a whole number.
Parameters
-
expression: The numeric expression to round up.
Example (MongoDB Shell)
This example demonstrates how to use the $ceil operator to round up a numeric field.
Create sample documents
db.numbers.insertMany([ { "_id": 1, "value": 3.14 }, { "_id": 2, "value": -2.7 }, { "_id": 3, "value": 0 } ])
Query example
db.numbers.aggregate([ { $project: { "roundedUp": { $ceil: "$value" } }} ])
Output
{ "_id": 1, "roundedUp": 4 }
{ "_id": 2, "roundedUp": -2 }
{ "_id": 3, "roundedUp": 0 }
Code examples
To view a code example for using the $ceil command, choose the tab for the language that you want to use: