对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。

$toUpper(表达式操作符)

$toUpper

将字符串转换为大写,并返回结果。

$toUpper 通过以下语法实现:

{ $toUpper: <expression> }

该参数可以是任何表达式,只要解析为字符串即可。有关表达式的更多信息,请参阅表达式。

如果参数解析为空值,$toUpper 将返回一个空字符串 ""。

$toUpper 仅对 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 }] )

以下操作使用$toUpper操作符返回大写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: "" }
给本页内容打分

在此页面上