Skip to content
VibORM
Esc
navigateopen⌘Jpreview
On this page

findFirst

Find the first record matching a filter, or null

findFirst returns the first record matching the filter, or null if none match. It takes the same options as findMany (where, orderBy, select, include, pagination) but returns a single record.

const user = await client.user.findFirst({
  where: { email: { contains: "alice" } },
});
// Type: User | null

Add an orderBy for a stable “first”:

const newest = await client.post.findFirst({
  where: { published: true },
  orderBy: { createdAt: "desc" },
});

findFirstOrThrow

Same as findFirst, but throws NotFoundError instead of returning null:

const user = await client.user.findFirstOrThrow({
  where: { email: "alice@example.com" },
});
// Type: User (never null)

Was this page helpful?