MongoDB 提供了不同類型的中使用的算術表達式運算符聚合管道階段和 $ceil 操作符就是其中之一。這操作員用於查找大於或等於指定數字的最小整數。
{ $ceil: <number> }
在這裏,數字是一個有效的表達式,直到它解析為一個數字。
- 如果輸入的值為空,則此運算符將返回空。
- 如果輸入的值為 NaN,則此運算符將返回 NaN。
- 如果輸入的值是缺失字段,則此運算符將返回 null。
例子:
在以下示例中,我們正在使用:
Database: GeeksforGeeks
Collection:employee
Document: three documents that contain the details of the employees in the form of field-value pairs.
使用 $ceil 運算符:
在這個例子中,我們將找出開發部門中大於或等於 perfoPoint 字段值的最小整數。
db.employee.aggregate([{$match:{department:"Development"}}, {$project:{perfoPoint:1, ceilingPoint:{$ceil:"$perfoPoint"}}}])
在嵌入式文檔中使用 $ceil 運算符:
在這個例子中,我們將找出大於或等於人力資源部門 perfoPoint.firstMonthPoint 字段值的最小整數。
db.employee.aggregate([{$match:{department:"HR"}}, ... {$project:{"perfoPoint.firstMonthPoint":1, ceilingPoint:{$ceil:"$perfoPoint.firstMonthPoint"}}}])
相關用法
- MongoDB $mul用法及代碼示例
- MongoDB $rename用法及代碼示例
- MongoDB $setOnInsert用法及代碼示例
- MongoDB $ln用法及代碼示例
- MongoDB $floor用法及代碼示例
- MongoDB $divide用法及代碼示例
- MongoDB $add用法及代碼示例
- MongoDB $sqrt用法及代碼示例
- MongoDB $multiply用法及代碼示例
- MongoDB $mod用法及代碼示例
- MongoDB $log10用法及代碼示例
- MongoDB $log用法及代碼示例
- MongoDB $abs用法及代碼示例
- MongoDB $strcasecmp用法及代碼示例
- MongoDB $toLower用法及代碼示例
注:本文由純淨天空篩選整理自ankita_saini大神的英文原創作品 MongoDB $ceil Operator。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。