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

$toUpper (aggregation)

項目一覧

$toUpper

Converts a string to uppercase, returning the result.

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

{ $toUpper: <expression> }

The argument can be any as long as it resolves to a string. For more information on expressions, see 式演算子.

If the argument resolves to null, $toUpper returns an empty string "".

$toUpperは ASCII 文字の string に対してのみ、明確に定義された動作を行います。

以下のドキュメントを持つinventoryコレクションを考えてみましょう。

db.inventory.insertMany( [
{ "_id" : 1, "item" : "ABC1", quarter: "13Q1", "description" : "PRODUCT 1" },
{ "_id" : 2, "item" : "abc2", quarter: "13Q4", "description" : "Product 2" },
{ "_id" : 3, "item" : "xyz1", quarter: "14Q2", "description" : null }
] )

The following operation uses the $toUpper operator to return uppercase item and uppercase description values:

db.inventory.aggregate(
[
{
$project:
{
item: { $toUpper: "$item" },
description: { $toUpper: "$description" }
}
}
]
)

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

{ "_id" : 1, "item" : "ABC1", "description" : "PRODUCT 1" }
{ "_id" : 2, "item" : "ABC2", "description" : "PRODUCT 2" }
{ "_id" : 3, "item" : "XYZ1", "description" : "" }

項目一覧