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

Prisma · Function

prisma.findUnique

findUnique() retrieves one Prisma record by an ID, unique field, or compound unique key. It can shape the result with select/include and returns null when no record matches.

How it works

Call the model delegate's findUnique method with a where filter containing an ID, unique field, or compound unique key. The method returns one matching record, optionally restricted with select or expanded with include; if no record matches, the result is null.

Syntax

prisma.<model>.findUnique({ where, select?, include? })

Parameters

NameTypeDescription
argsModelFindUniqueArgsOptions object containing where and optional result-shaping or relation-loading arguments; the exact generated type depends on the model.

Returns

A Promise resolving to the matching model record, shaped by select/include, or null when no record matches.

Key points

  • Use findUnique when the application needs one record identified by an ID or unique attribute.
  • A field with a unique constraint, such as email, can be used in the where filter.
  • Repeated compatible findUnique calls may be automatically batched by Prisma Client's dataloader.
  • Compound identifiers can be queried by supplying all fields through the generated compound-key filter.
  • Use select to restrict the response to explicitly requested scalar fields.

Common mistakes

  • The filter must identify a unique record; use an ID, a field marked unique, or a compound unique constraint rather than arbitrary fields.
  • findUnique does not throw when no record exists; use findUniqueOrThrow when absence should raise an exception.

Example: Find a user by a unique email

const user = await prisma.user.findUnique({
  where: { email: "alice@prisma.io" },
  select: { id: true, name: true }
});

Retrieves the selected fields for the user whose email is unique.

When to use it

Fetch by ID

Load one account by its primary key during a request.

Resolve a unique attribute

Look up a user by an email address declared unique in the schema.

Query a compound key

Retrieve an entity identified by multiple fields under a compound constraint.

Shape the selected result

Return only fields needed by an API response.

Interview questions

QWhat does findUnique do when no record matches?

findUnique retrieves at most one record using a unique identifier, such as an ID or unique attribute. If no matching record exists, it returns null.

Follow-up: How would you retrieve only selected columns? Add a select object, for example select: { name: true, profileViews: true }.

QHow can findUnique query a compound unique constraint?

Pass the model delegate a where object whose value identifies a unique record, such as { id: 42 } or { email: "alice@prisma.io" }. A compound unique constraint is represented by its generated or custom compound-key field containing the constituent values.

Follow-up: What alternative exists when missing data should be exceptional? Use findUniqueOrThrow(), which retrieves the record in the same way but throws if it is absent.

QHow can the returned data be shaped?

Use select to specify returned fields or include to request related records. These options shape the result while the where clause still determines the unique record being queried.

Follow-up: What performance behavior can occur across repeated lookups? Prisma Client's dataloader can automatically batch findUnique queries.

  • findUniqueOrThrow()
  • select
  • include
  • @@unique
  • @@id

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