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

Prisma · Const

startsWith

startsWith is a Prisma Client string filter that selects records whose field value begins with a specified prefix. Use it inside a string field’s where condition.

How it works

Use startsWith inside a string field's where filter to match records whose value begins with a specified prefix. It is applied through Prisma Client query methods such as findMany, and can be combined with other filtering operators.

Syntax

{ field: { startsWith: string } }

Parameters

NameTypeDescription
startsWithstringThe string prefix that the field value must begin with.

Returns

A Prisma Client query result containing records whose selected string field starts with the supplied prefix.

Key points

  • Use it to retrieve records whose string field begins with a chosen prefix.
  • The operator belongs in Prisma Client's where query option.
  • Combine prefix matching with logical operators to express alternative or compound conditions.
  • Supported operators can opt into case-insensitive filtering through the documented filter mode.

Common mistakes

  • Matching may be case-sensitive or case-insensitive depending on the database provider and its collation settings.
  • On supported PostgreSQL filters, use the mode property when you need explicit case-insensitive matching.

Example: Filter posts by title prefix

const result = await prisma.post.findMany({
  where: {
    title: {
      startsWith: "Pr",
    },
  },
});

Returns posts whose title begins with the specified string.

When to use it

Prefix-based title search

Find posts whose titles begin with a known prefix.

Composed prefix conditions

Build alternative filters for different initial characters or prefixes.

Case-aware filtering

Apply prefix matching while respecting database-specific case rules.

Interview questions

QWhat does startsWith do in Prisma Client?

startsWith is a Prisma Client string filter used inside a field's where condition. For example, { title: { startsWith: "Pr" } } selects records whose title begins with Pr.

Follow-up: How would you combine it with another condition? Use logical operators such as OR, AND, or NOT around the field filters.

QWhere is startsWith placed in a Prisma query?

Place the operator under the string field in the where object, then execute a query such as findMany. The operator accepts the prefix string to match.

Follow-up: How can matching behavior vary across databases? Case sensitivity is determined by the provider and collation, so inspect those settings or use a supported case-insensitive mode.

QIs startsWith always case-sensitive?

The result is affected by database case-sensitivity rules rather than by a universal Prisma default. PostgreSQL supports mode for specific case-insensitive filters.

Follow-up: What broader filtering capability does Prisma provide? Filters can target model fields and related record fields and can be composed with logical operators.

  • contains
  • endsWith
  • mode
  • OR
  • AND
  • NOT

Source: Prisma Client API (Prisma ORM v7). Checked 2026-10-16.