$toLower (聚合)
定义
行为
$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 } ] )
以下操作使用 $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" : "" }