MongoDB聚合运算符:$toLower
文章目录
- MongoDB聚合运算符:$toLower
- 语法
- 使用
- 举例
- 角度的双曲正切
 
 
$toLower聚合运算符用于将字符串转换为小写。 
 
语法
{ $toLower: <expression> }
- <expression>为可被解析为字符串的表达式。
- 如果参数解析为null,则返回空字符串""。
使用
$toLower仅对ASCII字符串具有明确定义的行为。换而言之,对其他字符无效。
举例
角度的双曲正切
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" : "" }