Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Prisma · Const

endsWith

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.

How it works

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.

Syntax

{ field: { endsWith: "suffix" } }

Parameters

NameTypeDescription
endsWithstringThe string suffix that the selected field must end with.

Returns

A Prisma Client query result containing records whose selected string field ends with the supplied suffix.

Key points

  • Use endsWith within a Prisma Client where clause to narrow returned records by a string suffix.
  • Combine suffix matching with OR, AND, or NOT to express compound conditions.
  • The filter is nested under the target scalar field inside the query's where object.

Example: Filter users by email suffix

const users = await prisma.user.findMany({
  where: {
    email: {
      endsWith: "prisma.io",
    },
  },
});

Retrieves users whose email field ends with the specified domain.

When to use it

Domain filtering

Find accounts whose email addresses use a particular domain suffix.

Suffix-based searches

Select records whose names, labels, or codes share a required ending.

Compound filters

Combine alternative or exclusionary suffix rules in one query.

Interview questions

QWhat does Prisma Client's 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" } }] }.

QWhere is 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.

QCan 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.

  • contains
  • startsWith
  • OR
  • AND
  • NOT
  • where
  • orderBy

Source: Filtering and sorting (Prisma ORM v7) | Prisma Documentation. Checked 2026-10-16.