On this page
$toLower (aggregation)
在本页面
Definition
$toLower
- 将字符串转换为小写,返回结果。
$toLower具有以下语法:
{ $toLower: <expression> }
参数可以是任何expression,只要它解析为字符串即可。有关表达式的更多信息,请参见Expressions。
如果参数解析为 null,则$toLower返回空字符串""
。
Behavior
$toLower仅对于 ASCII 字符字符串具有明确定义的行为。
Example
考虑包含以下文档的inventory
集合:
{ "_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 }
以下操作使用$toLower运算符返回小写item
和小写description
的值:
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" : "" }