0
0
NextJSframework~10 mins

Why database access matters in NextJS - Test Your Understanding

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

Complete the code to import the database client in a Next.js server component.

NextJS
import [1] from '@/lib/dbClient';
Drag options to blanks, or click blank then click option'
AdbClient
BReact
CuseState
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Importing React instead of the database client
Using useState which is a React hook
Trying to import fetch as the database client
2fill in blank
medium

Complete the code to fetch all users from the database using the client.

NextJS
const users = await dbClient.[1].findMany();
Drag options to blanks, or click blank then click option'
Acreate
Bdelete
CfindMany
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using create instead of findMany
Using delete or update which modify data
3fill in blank
hard

Fix the error in the code to correctly fetch a user by ID.

NextJS
const user = await dbClient.user.findUnique({ where: { id: [1] } });
Drag options to blanks, or click blank then click option'
AuserId
Bid
Cuser.id
DuserId.value
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not match the field
Using dot notation incorrectly
4fill in blank
hard

Fill both blanks to create a new user with name and email.

NextJS
await dbClient.user.create({ data: { name: [1], email: [2] } });
Drag options to blanks, or click blank then click option'
A"Alice"
B"alice@example.com"
CuserName
DuserEmail
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of string literals
Missing quotes around strings
5fill in blank
hard

Fill all three blanks to update a user's email by ID.

NextJS
await dbClient.user.update({ where: { id: [1] }, data: { email: [2] }, select: { [3]: true } });
Drag options to blanks, or click blank then click option'
AuserId
B"newemail@example.com"
Cemail
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names
Not quoting the new email string
Selecting wrong fields