Logical Operators

NameDescription
$andjoins query clauses with a logical AND, returns records that match all the clauses.
$orjoins query clauses with a logical OR, returns records that match any of the clauses.
$notjoins query clauses with a logical AND, returns records that do not match all the clauses.
$norjoins query clauses with a logical OR, returns records that do not match any of the clauses.

 

Example usage for the $and logical operator (default operator if unspecified):

await querier.findMany( User, { $project: ['id'], $filter: { name: 'maku', creatorId: 1 }, } );

or the same query with an explicit $and

await querier.findMany( User, { $project: ['id'], $filter: { $and: [{ name: 'maku' }, { creatorId: 1 }] }, } );

That ▲ code will generate this ▼ SQL:

SELECT `id` FROM `User` WHERE `name` = 'maku' AND `creatorId` = 1

 

Example usage for the $or logical operator:

await querier.findMany( User, { $project: ['id'], $filter: { $or: [{ name: 'maku' }, { creatorId: 1 }] }, } );

That ▲ code will generate this ▼ SQL:

SELECT `id` FROM `User` WHERE `name` = 'maku' OR `creatorId` = 1

 

Example usage for the $not logical operator

await querier.findMany( User, { $project: ['id'], $filter: { $not: [{ name: 'maku' }, { creatorId: 1 }] }, } );

That ▲ code will generate this ▼ SQL:

SELECT `id` FROM `User` WHERE NOT (`name` = 'maku' AND `creatorId` = 1)

 

Example usage for the $nor logical operator

await querier.findMany( User, { $project: ['id'], $filter: { $nor: [{ name: 'maku' }, { creatorId: 1 }] }, } );

That ▲ code will generate this ▼ SQL:

SELECT `id` FROM `User` WHERE NOT (`name` = 'maku' OR `creatorId` = 1)