Getting "The 'mongodb' provider is not supported with this command" Error when try to do mongoDB migrate with Prisma
Asked Answered
C

4

5

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?

Carver answered 13/8, 2022 at 11:58 Comment(0)
C
20

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

Carver answered 13/8, 2022 at 12:11 Comment(0)
S
7

According to the official documentation (https://www.prisma.io/docs/concepts/components/prisma-migrate):

Prisma Migrate:

Does not apply for MongoDB Instead of migrate dev and related commands, use db push for MongoDB.

i.e

npx prisma db push
Sava answered 31/10, 2023 at 20:54 Comment(0)
S
1

In prisma docs: prisma docs

"Whenever you make changes to your Prisma schema in the future, you manually need to invoke prisma generate in order to accommodate the changes in your Prisma Client API."

Schreiner answered 23/3, 2023 at 0:25 Comment(0)
P
1

To avoid confusion, follow these steps for a complete solution:

// Generate prisma/schema.prisma (and .env)
npx prisma init

// Generate assets based on schema file
npx prisma generate 

// Save to the actual database server
npx prisma db push 
Prance answered 9/6 at 6:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.