Omit records with selected IDs
Exclude known identifiers
Prisma · Const
notIn excludes records whose scalar field matches any value in a supplied list. Use it as a nested field filter in Prisma Client queries.
Use notIn inside a scalar field filter to exclude records whose field value matches any value in the supplied list. It is useful when the unwanted values are known as an array, and it can be combined with other conditions in a where object.
{ field: { notIn: values } }| Name | Type | Description |
|---|---|---|
values | Scalar[] | An array of scalar values to exclude from the selected field. |
A Prisma Client query result containing records whose filtered field is not equal to any supplied value.
notIn is used within Prisma Client's where filtering API to restrict which records a query returns.AND, OR, and NOT when a query needs compound conditions.const users = await prisma.user.findMany({
where: {
id: { notIn: [1, 2, 3] },
},
});This query returns users whose id is not one of the listed values.
Exclude known identifiers
Filter lifecycle values
Build compound queries
notIn filter do?notIn is a Prisma Client scalar filter that excludes records whose field equals any value in the provided list. For example, id: { notIn: [1, 2, 3] } omits those IDs.
Follow-up: How would you combine exclusion with another condition? Put notIn inside the field's filter object and add the other field conditions under the same where object.
notIn condition?Use the object form of the filter: where: { status: { notIn: ["ARCHIVED", "DELETED"] } }. This expresses the excluded values explicitly and works with Prisma Client's filter syntax.
Follow-up: Why should an older array shortcut not be used? Prisma ORM 5 removed the in and notIn shortcuts, so the nested filter form is required.
notIn differ from NOT?notIn is appropriate when exclusion is based on a finite list of scalar values. It differs from NOT, which is a logical operator for negating a broader condition or grouping conditions.
Follow-up: When would NOT be preferable? Use NOT when negating another filter expression rather than simply excluding listed scalar values.
innotANDORNOT