参考 > 参考 > 经营者 > 聚合管道运营商 > $ toUpper(汇总)
在本页面
$toUpper
将字符串转换为大写,返回结果。
$toUpper 具有以下语法:
{ $toUpper: <expression> }
该参数可以是任何表达式 ,只要它可以解析为字符串即可。有关表达式的更多信息,请参见表达式。
如果参数解析为null,则$toUpper返回一个空字符串""。
""
$toUpper 仅对于ASCII字符字符串具有明确定义的行为。
考虑inventory包含以下文档的集合:
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 }
以下操作使用$toUpper运算符返回大写item和大写description值:
item
description
db.inventory.aggregate( [ { $project: { item: { $toUpper: "$item" }, description: { $toUpper: "$description" } } } ] )
该操作返回以下结果:
{ "_id" : 1, "item" : "ABC1", "description" : "PRODUCT 1" } { "_id" : 2, "item" : "ABC2", "description" : "PRODUCT 2" } { "_id" : 3, "item" : "XYZ1", "description" : "" }