0
0
NestJSframework~10 mins

Query builder in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a query builder for the User entity.

NestJS
const userQuery = dataSource.getRepository(User).[1]();
Drag options to blanks, or click blank then click option'
Adelete
Bfind
Csave
DcreateQueryBuilder
Attempts:
3 left
💡 Hint
Common Mistakes
Using repository methods like find or save instead of createQueryBuilder.
2fill in blank
medium

Complete the code to add a WHERE clause filtering users by age.

NestJS
const users = await userQuery.where('user.age [1] :age', { age: 18 }).getMany();
Drag options to blanks, or click blank then click option'
A>=
B=
C<=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which filters only age exactly 18.
Using '<=' which filters age less than or equal to 18.
3fill in blank
hard

Fix the error in the code to select only the 'name' and 'email' fields.

NestJS
const users = await userQuery.select(['user.name', [1]]).getMany();
Drag options to blanks, or click blank then click option'
A'name'
B'user.email'
C'user.age'
D'email'
Attempts:
3 left
💡 Hint
Common Mistakes
Using field names without alias like 'email' causes errors.
Selecting wrong fields like 'name' again or 'user.age'.
4fill in blank
hard

Fill both blanks to order users by creation date descending and limit results to 5.

NestJS
const users = await userQuery.orderBy('user.createdAt', [1]).[2](5).getMany();
Drag options to blanks, or click blank then click option'
A'DESC'
B'ASC'
Climit
Dtake
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ASC' instead of 'DESC' for descending order.
Using 'limit' instead of 'take' which is the correct method.
5fill in blank
hard

Fill all three blanks to build a query that filters active users, selects their id and name, and orders by name ascending.

NestJS
const users = await userQuery.where('user.isActive = [1]').select(['user.[2]', 'user.[3]']).orderBy('user.name', 'ASC').getMany();
Drag options to blanks, or click blank then click option'
Atrue
Bid
Cname
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'false' instead of 'true' for active filter.
Selecting wrong fields or missing alias prefix.