Domain filtering
Find accounts whose email addresses use a particular domain suffix.
Prisma · Const
endsWith is a Prisma Client string filter for selecting records whose field value ends with a specified suffix. Put it inside the field condition of a where clause.
In Prisma Client, place endsWith inside a string field filter within where. It matches records whose field value has the supplied suffix and can be combined with logical operators such as OR, AND, and NOT.
{ field: { endsWith: "suffix" } }| Name | Type | Description |
|---|---|---|
endsWith | string | The string suffix that the selected field must end with. |
A Prisma Client query result containing records whose selected string field ends with the supplied suffix.
endsWith within a Prisma Client where clause to narrow returned records by a string suffix.OR, AND, or NOT to express compound conditions.where object.const users = await prisma.user.findMany({
where: {
email: {
endsWith: "prisma.io",
},
},
});Retrieves users whose email field ends with the specified domain.
Find accounts whose email addresses use a particular domain suffix.
Select records whose names, labels, or codes share a required ending.
Combine alternative or exclusionary suffix rules in one query.
endsWith filter do?endsWith is a Prisma Client string filter used inside a field condition in where. For example, { email: { endsWith: "prisma.io" } } selects users whose email ends with that text.
Follow-up: How would you match either of two suffixes? Use OR with separate field filters, such as { OR: [{ email: { endsWith: "gmail.com" } }, { email: { endsWith: "company.com" } }] }.
endsWith placed in a Prisma query?It is applied as a nested condition on the field being filtered, rather than as a top-level query option. A findMany query can therefore use it under where.email.
Follow-up: How can an exclusion be added? Put a matching condition under NOT, for example a NOT filter for emails ending in an administrative domain.
endsWith be combined with other conditions?endsWith can participate in compound filtering with Prisma's logical operators. This lets a query include records matching alternative suffixes or exclude records matching an unwanted suffix.
Follow-up: Can the same approach filter JSON values? The reference page also documents JSON-specific operators such as string_ends_with, which are distinct from the scalar string filter.
containsstartsWithORANDNOTwhereorderBy