Rounding decimals in MongoDB with $ceil

$Ceil is the function that is used to round a double to floor or ceiling. $ceil comes under the mongo aggregate function, below is the example Mongo statement to retrieve data based on ceiling

Let’s assume below is the cloths collection.

{"_id" : 110, "Price" : 10.35 }
{"_id" : 120, "Price" : 17.83 }
{"_id" : 130, "Price" : 16.52 }
{"_id" : 140, "Price" : -99.54}


db.cloths.aggregate([{
$project:"beforeRound":"$Price","roundedvalue":$ceil:"$Price"}}
}])


Output for cloths collection and above Statement is:


{ "_id" : 110, "beforeRound" : 10.35, "roundedvalue" : 11 }
{ "_id" : 120, "beforeRound" : 17.83, "roundedvalue" : 18 }
{ "_id" : 130, "beforeRound" : 16.52, "roundedvalue" : 17 }
{ "_id" : 140, "beforeRound" : -99.54, "roundedvalue" : -99 }


$ceil is used to round the decimal values.
$project is used to retrieve the specific columns from collection.
$price is used to project the price value from the mongo node.