Definition定义
$toLowerConverts a string to lowercase, returning the result.将字符串转换为小写,并返回结果。$toLowerhas the following syntax:具有以下语法:{ $toLower: <expression> }The argument can be any expression as long as it resolves to a string.参数可以是任何表达式,只要它解析为字符串即可。For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。If the argument resolves to null,如果参数解析为$toLowerreturns an empty string"".null,$toLower将返回一个空字符串""。
Behavior行为
$toLower only has a well-defined behavior for strings of ASCII characters.仅对ASCII字符串具有明确定义的行为。
Example示例
Consider a 考虑使用以下文件进行inventory collection with the following documents: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:$toLow运算符返回小写item和小写description值:
db.inventory.aggregate(
[
{
$project:
{
item: { $toLower: "$item" },
description: { $toLower: "$description" }
}
}
]
)
The operation returns the following results:该操作返回以下结果:
{ _id: 1, item: "abc1", description: "product 1" }
{ _id: 2, item: "abc2", description: "product 2" }
{ _id: 3, item: "xyz1", description: "" }