Nest Js + Prisma,mongodb的身份验证错误

dm7nw8vv  于 2023-08-04  发布在  Go
关注(0)|答案(1)|浏览(164)

在NestJs+Prisma项目的终端中运行npx prisma db push命令时,出现以下身份验证错误

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": MongoDB database "test" at "localhost:27017"
Error: MongoDB error
SCRAM failure: Authentication failed.
   0: schema_core::commands::schema_push::Calculate `from`
             at schema-engine/core/src/commands/schema_push.rs:29
   1: schema_core::state::SchemaPush
             at schema-engine/core/src/state.rs:432

字符串
我正在使用Prisma连接mongodb,使用以下代码

generator client {
  provider = "prisma-client-js"
}

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

model User {
  id                  String       @id @default(uuid()) @map("_id")
  createdAt           DateTime     @default(now())
  updatedAt           DateTime     @updatedAt
  emailId             String
  @@index([emailID])
}


.env文件中的数据库字符串是

// DB Name is test
DATABASE_URL="mongodb://user:password@localhost:27017/test?authMechanism=SCRAM-SHA-1"


我正在使用以下版本的Prisma & Prisma-Client

"@prisma/client": "^5.0.0",
"prisma": "^5.0.0",

ymdaylpp

ymdaylpp1#

authSource=admin添加到URL参数。新的URL应该是这样的:

mongodb://user:password@localhost:27017/test?authSource=admin&authMechanism=SCRAM-SHA-1

字符串

相关问题