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

Prisma · Const

contains

contains is a Prisma Client string filter that matches records whose selected field includes a specified substring. Combine it with mode: "insensitive" for case-insensitive matching.

How it works

Use contains inside a string field's where filter to select records whose value includes a specified substring. Add mode: "insensitive" when the query should ignore letter casing, as shown in the Prisma Client reference example.

Syntax

{ field: { contains: string, mode?: "default" | "insensitive" } }

Parameters

NameTypeDescription
containsstringSubstring to search for in the selected string field.
modeQueryModeControls case sensitivity; use insensitive for case-insensitive matching.

Returns

A filtered Prisma Client query result containing records whose selected string field includes the requested substring.

Key points

  • contains is one of Prisma Client's string filter operators, alongside operators such as startsWith.
  • The reference documents a query that filters records by a title containing a substring while ignoring case.
  • String filters are applied through Prisma Client's where query option.
  • A contains condition can participate in compound filtering with Prisma's logical operators.

Common mistakes

  • Case-insensitive matching requires the mode: "insensitive" option; contains alone does not request case-insensitive behavior.

Example: Case-insensitive substring filter

const posts = await prisma.post.findMany({
  where: {
    title: {
      contains: "Prisma",
      mode: "insensitive",
    },
  },
});

Returns posts whose title contains “Prisma”, ignoring letter case.

When to use it

Substring search

Search posts by title or other text fields for a user-provided term.

Case-insensitive search

Match text regardless of capitalization, such as names or titles entered inconsistently.

Combined filtering

Use a text condition together with other field predicates in a compound where clause.

Interview questions

QWhat does the contains filter do?

contains is a Prisma Client string filter used inside a field condition in where. It matches records whose field value includes the supplied substring.

Follow-up: How would you make the match case-insensitive? Add mode: "insensitive" alongside contains in the same field filter.

QHow is contains written in a Prisma Client query?

Place contains in the string field's filter object, for example title: { contains: "Prisma" }. The surrounding query can be a normal Prisma Client operation such as findMany.

Follow-up: How can the filter be combined with another condition? Add another field condition or compose conditions with Prisma's logical operators such as AND or OR.

QHow do you perform a case-insensitive contains query?

The documented example combines contains: "Prisma" with mode: "insensitive" to match the substring without regard to case. This is useful when users may enter different capitalization.

Follow-up: What broader query feature contains this operator? Prisma Client filtering uses the where option, which supports multiple field conditions and logical operators.

  • startsWith
  • endsWith
  • where
  • OR
  • AND
  • NOT

Source: Prisma Client API. Checked 2026-10-16.