Documentation
Database [PRO]

Database [PRO]

For storing data, Prisma ORM (opens in a new tab) is used in conjunction with MongoDB. Both are very flexible. You can easily shape your data models whatever you want. If another database is prefered, it can be swapped without much work. Refer to the Prisma docs (opens in a new tab).

The database configuration and schema are located at its own package packages/database/.

MongoDB Setup

  1. First you need an account on MongoDB Atlas (opens in a new tab).

  2. Create a new project and select it in the navbar.

  3. Create a new deployment.

a. Click Create a deployment. Select the M0 tier as it's free and great for testing purposes. The name can be left as is. Untick both Add sample dataset as we have our own schema and Automate security setup. Select the provider and region if needed. Click Create Deployment.

b. In the following window, click Allow access from anywhere and add IP Address. Create a database user by choosing a username and password and clicking Create Database User. Write down the username and password. This user will be used to access the database.

If you have troubles connecting to the database, make sure your domain or local IP is added in Network Access.

c. Now click Choose a connection method, then Drivers and there you should see the connecting string with your user's username and password. This string will be used by Prisma to connect to the database, and should look similar to this mongodb+srv://<username>:<password>@<uri>/?retryWrites=true&w=majority&appName=Cluster0 - write it down.

d. Copy it and paste it into the .env file, replacing the username and password with the database user's credentials. Click Review setup steps and Done, and now the database should be ready to go.

PRISMA_MONGODB_DATABASE_URL=

Prisma can fail with the The provided database string is invalid error. If this happens, change the connection string from mongodb+srv://<username>:<password>@<uri>/?retryWrites=true&w=majority&appName=Cluster0 to mongodb+srv://<username>:<password>@<uri>/Cluster0?retryWrites=true&w=majority.

  1. Run pnpm db:push to push the schema to MongoDB Atlas.

  2. Done! Now it's possible to sign up, log in and do other actions related to storing data in the database.

Prisma Scripts

The following scripts are available locally.

  1. The step for generating schema types is run on postinstall but when you need to regenerate types run
pnpm db:generate
  1. To push the schema changes, run
pnpm db:push