db.command.aggregate.gt
1. Operator Description
Function: Compares two values and returns true
if the former is greater than the latter, otherwise returns false
.
Declaration: db.command.aggregate.gt([value1, value2])
2. Operator Parameters
Field | Type | Required | Description |
---|---|---|---|
- | <Array>Expression | Required | array of aggregate expressions |
3. Sample Code
Suppose the collection price
contains the following records:
{ "_id": 1, "value": 10 }
{ "_id": 2, "value": 80 }
{ "_id": 3, "value": 50 }
Check whether value
is greater than 50.
// 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('price')
.aggregate()
.project({
matched: $.gt(['$value', 50])
})
.end()
console.log(res.data)
}
The returned result is as follows:
{ "_id": 1, "matched": false }
{ "_id": 2, "matched": true }
{ "_id": 3, "matched": false }