Bird
0
0

Identify the error in this NestJS Prisma Client usage:

medium📝 Debug Q14 of 15
NestJS - Database with Prisma
Identify the error in this NestJS Prisma Client usage:
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

async function getUsers() {
const users = prisma.user.findMany();
return users;
}
AFunction getUsers should not be async
BMissing await before prisma.user.findMany()
CfindMany() does not exist on prisma.user
DPrismaClient should not be instantiated directly
Step-by-Step Solution
Solution:
  1. Step 1: Check async function usage

    prisma.user.findMany() returns a Promise, so it must be awaited inside async functions.
  2. Step 2: Identify missing await

    The code misses 'await' before the call, so it returns a Promise instead of resolved data.
  3. Final Answer:

    Missing await before prisma.user.findMany() -> Option B
  4. Quick Check:

    Async DB calls need await [OK]
Quick Trick: Await all Prisma async calls inside async functions [OK]
Common Mistakes:
  • Forgetting await on async Prisma calls
  • Thinking PrismaClient can't be instantiated
  • Assuming findMany() is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes