Negative field filtering
Exclude records matching a field condition, such as posts whose content contains a particular term.
Prisma · Const
NOT is a Prisma Client logical filter that excludes records matching a nested condition. It can be combined with other where operators to express compound inclusion and exclusion rules.
In a Prisma Client where filter, NOT negates a nested condition. A record matches only when every condition inside NOT evaluates to false, making it useful for excluding records that satisfy a field filter or a compound condition.
NOT: { <field>: <filter> }| Name | Type | Description |
|---|---|---|
NOT | Prisma Client where filter | A nested Prisma Client filter object containing one or more field conditions to negate. |
Records or aggregate results that do not satisfy the nested filter, depending on the Prisma Client operation.
NOT only when every nested condition evaluates to false.NOT alongside OR to include several alternatives while excluding a specific matching subset.count, not only record retrieval.NOT does not include rows whose value is NULL; combine OR with an explicit null condition when those rows must be retained.const users = await prisma.user.findMany({
where: {
NOT: {
email: {
endsWith: "admin.example.com",
},
},
},
});Fetches users whose email does not end with the excluded domain.
Exclude records matching a field condition, such as posts whose content contains a particular term.
Combine alternatives with an exclusion, such as accepting multiple email domains while rejecting an administrative subdomain.
Apply the same negated condition while counting matching records.
NOT operator do?NOT is a Prisma Client filtering operator that excludes records matching its nested condition. For example, placing content: { contains: "databases" } inside NOT returns posts whose content does not contain that text.
Follow-up: How would you include nullable rows? Add an OR branch that explicitly matches null, alongside the negated condition.
NOT behave with compound filters?A record passes a NOT filter when all conditions inside it evaluate to false. It can be combined with OR and other where conditions to express inclusion and exclusion rules in one query.
Follow-up: How does this differ from a field-level not? The field-level form negates one field comparison, while NOT negates a nested filter object.
NOT be used and what can it contain?Use NOT inside a model operation's where object, such as findMany or count. The nested object uses normal Prisma field filters, including operators such as contains or endsWith.
Follow-up: What limitation applies to JSON fields? Prisma's documented filter conditions cannot be used to filter fields with the JSON data type.
ANDORnotisNot