Session: Querying: How to Use NOT Operator
IDocumentQuery
contains NOT
operator which can be used to negate next predicate
Note
NOT
operator cannot be used alone without succeeding predicate.
Example I
// load all entities from 'Employees' collection
// where firstName NOT equals 'Robert'
const employees = await session.advanced
.documentQuery({ collection: "Employees" })
.not()
.whereEquals("FirstName", "Robert")
.all();
Example II
// load all entities from 'Employees' collection
// where firstName NOT equals 'Robert'
// and lastName NOT equals 'King'
const employees = await session.advanced
.documentQuery({ collection: "Employees" })
.not()
.openSubclause()
.whereEquals("FirstName", "Robert")
.andAlso()
.whereEquals("LastName", "King")
.closeSubclause()
.all();
Example III
// load all entities from 'Employees' collection
// where firstName NOT equals 'Robert'
// and lastName NOT equals 'King'
// identical to 'Example II' but 'whereNotEquals' is used
const employees = await session.advanced
.documentQuery({ collection: "Employees" })
.whereNotEquals("FirstName", "Robert")
.andAlso()
.whereNotEquals("LastName", "King")
.all();