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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
