Skip to main content

whereNot

The whereNot method finds all records that do not match the provided clauses.

await User.whereNot({
email: ops.ilike('burpcollaborator.net'),
}).all()

whereNot takes a single condition object; all keys within it are AND'd together and the whole group is negated:

// WHERE NOT (status = 'archived' AND role = 'guest')
query.whereNot({ status: 'archived', role: 'guest' })
tip

Negation also matches rows whose column is NULL.

Chaining

You can chain multiple whereNot calls together, as well as chain them with other calls to where. This is useful for conditional query building:

let query = Post.whereNot({ name: null })

if (this.params.body) {
query = query.whereNot({ body: null })
}

await query.all()