Bird
0
0

Given this QueryBuilder snippet, what is the output?

medium📝 component behavior Q5 of 15
NestJS - Database with TypeORM
Given this QueryBuilder snippet, what is the output?
const count = await this.orderRepository.createQueryBuilder('order')
  .where('order.status = :status', { status: 'shipped' })
  .getCount();
ATotal number of orders ignoring status
BArray of orders with status 'shipped'
CNumber of orders with status 'shipped'
DUndefined because getCount() is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Understand getCount() method

    getCount() returns the number of records matching the query.
  2. Step 2: Analyze the where clause

    It filters orders where status equals 'shipped'.
  3. Final Answer:

    Number of orders with status 'shipped' -> Option C
  4. Quick Check:

    getCount() returns count of filtered records [OK]
Quick Trick: Use getCount() to get number of matching rows [OK]
Common Mistakes:
  • Confusing getCount() with getMany()
  • Ignoring the where filter
  • Thinking getCount() returns data array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes