Skip to main content

db.command.aggregate.neq

1. Operator Description

Function: Compares two values and returns true if they are not equal, otherwise returns false.

Declaration: db.command.aggregate.neq([value1, value2])

2. Operator Parameters

FieldTypeRequiredDescription
-<Array>ExpressionRequiredarray 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 }

Retrieve records where value is not equal to 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: $.neq(['$value', 50])
})
.end()
console.log(res.data)
}

The returned result is as follows:

{ "_id": 1, "matched": true }
{ "_id": 2, "matched": true }
{ "_id": 3, "matched": false }