Link MongoDB with Prisma
First to use in MongoDB Atlas, and deploy it to Vercel. Whole process:
- Prisma Usage:
1).Project initialization:
run npm init --yes
2).Installing Prisma:
run yarn add -D prisma
or npm i -D prisma
3).Generating Prisma project configuration:
run npx prisma init
4).Additionally, executing the above commands will automatically generate the following files:
prisma/schema.prisma: This is the Prisma schema file used to define your database models and relationships.
.env file: This is an environment variable file used to store sensitive information and configuration parameters, such as database connection details.
5).set schema.prisma
!! important: set .env
DATABASE_URL="mongodb+srv://test:test@cluster0.ns1yp.mongodb.net/myFirstDatabase/?retryWrites=true&w=majority"
You need to first create a database in MongoDB Atlas, then link to it.
use npx prisma db push
to deploy it to MongoDB Atlas
- How to deploy it to Vercel:
First, click Project Setting - Environment Variables
Then add new Key- Vaule pair:
DATABASE_URL + XXX
Add redeploy it, and it works !