Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
APPLIES TO:
MongoDB vCore
The $ceil
operator returns the smallest integer greater than or equal to the specified number.
Syntax
The syntax for the $ceil
operator is as follows:
{ $ceil: <number> }
Parameters
Description | |
---|---|
<number> |
Any valid expression that resolves to a number. If the expression resolves to null or refers to a missing field, $ceil returns null. |
Example
Let's understand the usage with sample data from the stores
dataset to calculate the ceiling value of average sales per staff member.
db.stores.aggregate([
{ $match: { "_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74" } },
{
$project: {
name: 1,
totalSales: "$sales.totalSales",
totalStaff: {
$add: ["$staff.totalStaff.fullTime", "$staff.totalStaff.partTime"]
},
ceiledAverageSalesPerStaff: {
$ceil: {
$divide: [
"$sales.totalSales",
{ $add: ["$staff.totalStaff.fullTime", "$staff.totalStaff.partTime"] }
]
}
}
}
}
])
This will produce the following output:
{
"_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
"name": "Proseware, Inc. | Home Entertainment Hub - East Linwoodbury",
"totalSales": 151864,
"totalStaff": 39,
"ceiledAverageSalesPerStaff": 3894
}
Related content
- Review options for Migrating from MongoDB to Azure Cosmos DB for MongoDB (vCore)
- Read more about Feature compatibility with MongoDB