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'
List<Employee> employees = session
.advanced()
.documentQuery(Employee.class)
.not()
.whereEquals("FirstName", "Robert")
.toList();
Example II
// load all entities from 'Employees' collection
// where firstName NOT equals 'Robert'
// and lastName NOT equals 'King'
List<Employee> employees = session
.advanced()
.documentQuery(Employee.class)
.not()
.openSubclause()
.whereEquals("FirstName", "Robert")
.andAlso()
.whereEquals("LastName", "King")
.closeSubclause()
.toList();
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
List<Employee> employees = session
.advanced()
.documentQuery(Employee.class)
.whereNotEquals("FirstName", "Robert")
.andAlso()
.whereNotEquals("LastName", "King")
.toList();