Bird
0
0

In a NestJS service, which Prisma Client method correctly retrieves a single user by their unique email?

easy📝 Syntax Q3 of 15
NestJS - Database with Prisma
In a NestJS service, which Prisma Client method correctly retrieves a single user by their unique email?
Aawait prisma.user.findMany({ where: { email: 'user@example.com' } });
Bawait prisma.user.findUnique({ where: { email: 'user@example.com' } });
Cawait prisma.user.findFirst({ where: { email: 'user@example.com' } });
Dawait prisma.user.findAll({ where: { email: 'user@example.com' } });
Step-by-Step Solution
Solution:
  1. Step 1: Identify the method to fetch a unique record

    The Prisma Client method findUnique is designed to retrieve a single record based on a unique field such as email or id.
  2. Step 2: Check the query syntax

    The correct syntax uses where: { email: 'user@example.com' } inside findUnique.
  3. Final Answer:

    await prisma.user.findUnique({ where: { email: 'user@example.com' } }); -> Option B
  4. Quick Check:

    Only findUnique guarantees a single unique record [OK]
Quick Trick: Use findUnique for unique fields like email or id [OK]
Common Mistakes:
  • Using findMany when expecting a single record
  • Using findAll which does not exist in Prisma Client
  • Using findFirst which may return the first match but not guaranteed unique

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes