Bird
0
0

Given this PrismaService method, what will console.log(users) output if the database has 3 users?

medium📝 component behavior Q4 of 15
NestJS - Database with Prisma
Given this PrismaService method, what will console.log(users) output if the database has 3 users?
async getUsers() {
  return this.prisma.user.findMany();
}
AAn array with 3 user objects
BA single user object
CUndefined
DAn error because findMany requires parameters
Step-by-Step Solution
Solution:
  1. Step 1: Understand findMany behavior

    The findMany() method returns an array of all matching records, here all users.
  2. Step 2: Consider database content

    Since the database has 3 users, the method returns an array with 3 user objects.
  3. Final Answer:

    An array with 3 user objects -> Option A
  4. Quick Check:

    findMany returns array of records = An array with 3 user objects [OK]
Quick Trick: findMany returns an array of matching records, even if empty [OK]
Common Mistakes:
  • Expecting a single object instead of array
  • Thinking findMany needs parameters
  • Confusing findMany with findUnique

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes