定義
$toLower文字列を小文字に変換し、結果を返します。
$toLowerの構文は次のとおりです。{ $toLower: <expression> } 引数は、string に変換される限り、式でもかまいません。 式の詳細については、「式 」を参照してください。
If the argument resolves to null,
$toLowerreturns an empty string"".
動作
$toLower は 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 } ] )
The following operation uses the $toLower operator return lowercase item and lowercase description value:
db.inventory.aggregate( [ { $project: { item: { $toLower: "$item" }, description: { $toLower: "$description" } } } ] )
この操作は次の結果を返します。
{ _id: 1, item: "abc1", description: "product 1" } { _id: 2, item: "abc2", description: "product 2" } { _id: 3, item: "xyz1", description: "" }