db.command.aggregate.not
1. Operator Description
Function: Given an expression, if the expression returns true
, then not
returns false
, otherwise returns true
.
Declaration: db.command.aggregate.not(expression)
2. Operator Parameters
Field | Type | Required | Description |
---|---|---|---|
- | Expression | Yes | If the expression returns false , null , 0 , or undefined , it resolves to false ; otherwise, all other return values are considered true . |
3. Sample Code
Suppose the collection price
contains the following records:
{ "_id": 1, "min": 10, "max": 100 }
{ "_id": 2, "min": 60, "max": 80 }
{ "_id": 3, "min": 30, "max": 50 }
Find records where min
is not greater than 40.
// 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({
fullfilled: $.not($.gt(['$min', 40]))
})
.end()
console.log(res.data)
}
The returned result is as follows:
{ "_id": 1, "fullfilled": true }
{ "_id": 2, "fullfilled": false }
{ "_id": 3, "fullfilled": true }