skip to Main Content

When I try to run any command from the prisma I get this error message:

$ npx prisma migrate reset

Error: MongoDB error
SCRAM failure: Authentication failed.
0: migration_core::state::Reset
at migration-engine/core/src/state.rs:341

When I run docker ps:

CONTAINER ID | IMAGE | COMMAND | CREATED | STATUS | PORTS | NAMES

388a7219da3d | mongo:latest | "docker-entrypoint.s…" | About an hour ago | Up About an hour | 0.0.0.0:27017->27017/tcp, :::27017->27017/tcp | auction-mongodb

my schema.prisma:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["mongodb"]
}

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

model Test {
  id String  @id @default(auto()) @map("_id") @db.ObjectId
  text String 
}

.env:

DATABASE_URL=mongodb://auction-user:password@localhost:27017/auction-db?authSource=admin

2

Answers


  1. Simply add ?authSource=admin to the end of your DATABASE_URL in .env file.

    Login or Signup to reply.
  2. in my case this code solved.
    user and pw suppose to have root role.

    DATABASE_URL="mongodb://root:example@localhost:3333/liz?retryWrites=true&w=majority&authSource=admin"
    
    DATABASE_URL="mongodb://username:password@ip:port/db?retryWrites=true&w=majority&authSource=admin"
    

    do remove +rsv if you want to connect to your local mongodb

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search