ANNOUNCEMENT: Voyage AI joins MongoDB to power more accurate and trustworthy AI applications on Atlas.
Learn more
Docs Menu

$ceil (aggregation)

項目一覧

$ceil

Returns the smallest integer greater than or equal to the specified number.

$ceilの構文は次のとおりです。

{ $ceil: <number> }

<number>式は、数値に変換される限り、どのような有効なでもかまいません。 式の詳細については、「式演算子 」を参照してください。

引数がnullの値に解決されるか、欠落しているフィールドを参照する場合、 $ceilnullを返します。 引数がNaNに解決されると、 $ceilNaNを返します。

結果

{ $ceil: 1 }

1

{ $ceil: 7.80 }

8

{ $ceil: -2.8 }

-2

次のドキュメントを含むsamplesという名前のコレクションを作成します。

db.samples.insertMany(
[
{ _id: 1, value: 9.25 },
{ _id: 2, value: 8.73 },
{ _id: 3, value: 4.32 },
{ _id: 4, value: -5.34 }
]
)

The following example returns both the original value and the ceiling value:

db.samples.aggregate([
{ $project: { value: 1, ceilingValue: { $ceil: "$value" } } }
])

この操作は次の結果を返します。

{ "_id" : 1, "value" : 9.25, "ceilingValue" : 10 }
{ "_id" : 2, "value" : 8.73, "ceilingValue" : 9 }
{ "_id" : 3, "value" : 4.32, "ceilingValue" : 5 }
{ "_id" : 4, "value" : -5.34, "ceilingValue" : -5 }

項目一覧