I'm developing some simple Todo App BE using NestJS with Prisma ORM and use MongoDB as the DB. I'm using a FREE and SHARED MongoDB cluster that is hosted in MongoDB Altas cloud. Also I added 0.0.0.0/0
to the network access tab so anyone can connect to the DB.
schema.prisma file
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Task {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String?
description String?
status TaskStatus @default(TODO)
}
enum TaskStatus {
TODO
INPROGRESS
DONE
}
.env file
DATABASE_URL="mongodb+srv://<username>:<password>@todoappdb.jfo3m2c.mongodb.net/?retryWrites=true&w=majority"
But when I try to run npx prisma migrate dev --name init
command it gives following output
D:\todoapp-backend>npx prisma migrate dev --name init
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db"
Error: The "mongodb" provider is not supported with this command. For more info see https://www.prisma.io/docs/concepts/database-connectors/mongodb
0: migration_core::state::DevDiagnostic
at migration-engine\core\src\state.rs:250
Can someone point me what is the problem?
After reading some content, found that prisma migrate
commands are for the SQL databases only since they have a rigid table structure. But MongoDB is a document database and those data are unstructured
So rather than running prisma migrate
command we can use following command
npx prisma generate
This command creates the Prisma client that gives type-safe access to our database.
Reference - https://www.youtube.com/watch?v=b4nxOv91vWI&ab_channel=Prisma