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

Prisma · Module

findUnique

findUnique() retrieves one record by ID, a unique field, or a compound unique key. It returns the matching record or null when no record exists, and supports selecting or including related data.

Since
2.12.0

How it works

Call findUnique() on a model delegate with a where object containing an ID, unique scalar field, or compound unique key. It returns one matching record, optionally shaped with select or include, or null when no record matches; use findUniqueOrThrow() when absence should raise an error.

Syntax

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

Parameters

NameTypeDescription
argsUserFindUniqueArgsAn object containing a unique where filter and optional payload-shaping options such as select or include.

Returns

A single model record matching the unique filter, or null when no record is found.

Key points

  • A field declared unique can be used to retrieve the matching record.
  • The method replaced the older findOne API in Prisma 2.12.0.
  • The throwing variant uses the same lookup approach as findUnique().
  • For a related single record, Prisma Client applies a unique filter to select the appropriate relation.

Common mistakes

  • Do not assume a missing record is returned as null when using findUniqueOrThrow(); that variant throws a PrismaClientKnownRequestError instead.

Example: Find a user by a unique field

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

if (user) {
  console.log(user.id, user.email);
}

Looks up one user by its unique email field and handles the null result when no matching record exists.

When to use it

Lookup by ID or unique field

Fetch one account by its primary key or unique email address.

Compound-key lookup

Retrieve one record using the combined values of a compound unique constraint.

Include related data

Return a user together with selected related records in one payload.

Fluent relation traversal

Traverse a to-one record into related data using chained relation calls.

Interview questions

QWhat does findUnique() query?

findUnique() retrieves one record by ID or by a field marked unique. Its where filter can also use a compound unique key, and the result may be null if no record matches.

Follow-up: How would you make absence exceptional? Use findUniqueOrThrow(), which retrieves the record in the same way but throws a PrismaClientKnownRequestError when none is found.

QHow do you query with a compound unique constraint?

A compound unique constraint is represented in where by its generated compound key, whose value is an object containing each constrained field. This lets the query identify one record using the combined unique values.

Follow-up: Can a compound unique key be used with arbitrary query methods? No; the documentation limits compound ID and compound unique constraint filters to unique queries such as findUnique() and findUniqueOrThrow(), as well as update, delete, and upsert operations.

QHow can the returned payload be shaped or extended?

Use select to choose returned scalar fields and nested relation fields, or include to include relations. The result can also be followed with the fluent API to fetch related data when the preceding call returns a single object.

Follow-up: What constraint applies to fluent chaining? Each preceding call must return only one object, such as a findUnique() result or a to-one relation.

  • findUniqueOrThrow()
  • findFirst()
  • findMany()
  • select
  • include
  • compound unique constraints
  • fluent API

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