Substring search
Search posts by title or other text fields for a user-provided term.
Prisma · Const
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.
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.
{ field: { contains: string, mode?: "default" | "insensitive" } }| Name | Type | Description |
|---|---|---|
contains | string | Substring to search for in the selected string field. |
mode | QueryMode | Controls case sensitivity; use insensitive for case-insensitive matching. |
A filtered Prisma Client query result containing records whose selected string field includes the requested substring.
contains is one of Prisma Client's string filter operators, alongside operators such as startsWith.where query option.contains condition can participate in compound filtering with Prisma's logical operators.mode: "insensitive" option; contains alone does not request case-insensitive behavior.const posts = await prisma.post.findMany({
where: {
title: {
contains: "Prisma",
mode: "insensitive",
},
},
});Returns posts whose title contains “Prisma”, ignoring letter case.
Search posts by title or other text fields for a user-provided term.
Match text regardless of capitalization, such as names or titles entered inconsistently.
Use a text condition together with other field predicates in a compound where clause.
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.
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.
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.
startsWithendsWithwhereORANDNOT