db.command.aggregate.toUpper
1. Operator Description
Function: Converts a string to uppercase and returns it.
Declaration: db.command.aggregate.toUpper(<expression>)
2. Operator Parameters
Field | Type | Required | Description |
---|---|---|---|
- | Expression | Required | As long as an expression can be parsed into a string, it is a valid expression. For example: $ + specified field . |
3. Sample Code
Suppose the collection students
contains the following records:
{ "firstName": "Yuanxin", "group": "a", "lastName": "Dong", "score": 84 }
{ "firstName": "Weijia", "group": "a", "lastName": "Wang", "score": 96 }
{ "firstName": "Chengxi", "group": "b", "lastName": "Li", "score": 80 }
Use toUpper
to convert the value of the lastName
field to uppercase:
// Sample code in the Cloud Function environment
const tcb = require('@cloudbase/node-sdk')
const app = tcb.init({
env: 'xxx'
})
const db = app.database()
const $ = db.command.aggregate
const _ = db.command
exports.main = async (event, context) => {
const res = await db
.collection('students')
.aggregate()
.project({
_id: 0,
result: $.toUpper('$lastName')
})
.end()
console.log(res.data)
}
The returned result is as follows:
{ "result": "DONG" }
{ "result": "WANG" }
{ "result": "LI" }