Docs Menu
Docs Home
/
データベース マニュアル
/ / /

$toUpper(集計)

$toUpper

string を大文字に変換し、結果を返します。

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

{ $toUpper: <expression> }

引数は、string に変換される限り、任意のにすることができます。 式の詳細については、「式演算子 」を参照してください。

引数が null に解決された場合、 $toUpperは空のstring "" を返します。

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

以下のドキュメントを持つ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 }
] )

次の操作では、 $toUpper演算子を使用して、大文字のitemと大文字のdescriptionの値を返します。

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: "" }

戻る

$toLower

項目一覧