Goal

The goal of this lesson is to get comfortable with the Prisma Client API and explore some of the available database queries you can send with it. You'll learn about CRUD queries, relation queries (like nested writes), filtering and pagination. Along the way, you will introduce a second model with a relation to the User model that you created before.

Setup

You can continue working in the same prisma-mongodb-workshop project that you set up in lesson 1. The script.ts file contains a main function that is invoked each time the script is executed.

Hints

Tasks

At the end of each task, you can run the script using the following command:

npm run dev

Task 1: Write a query to return all User documents

To warm yourself up a bit, go and write a query to return all User documents from the database. Print the result to the console using console.log.

Task 2: Write a query to create a new User ****document

In this task you'll create another User document. In your Prisma Client query, provide only a value for email but not for name:

Can you find the query that lets you do that?

Task 3: Write a query to update an existing User document