I am trying to write a Nuxt3 app using prisma and atlas MongoDB, I successfully set up all and npx prisma db push
works fine, But when I send queries to your database I get the following error:
"message": "\nInvalid `prisma.user.create()` invocation:\n\n\nThe provided
database string is invalid. MongoDB connection string error: invalid connection
string scheme: mongo in database URL. Please refer to the documentation in
https://www.prisma.io/docs/reference/database-reference/connection-urls for
constructing a correct connection string. In some cases, certain characters must
be escaped. Please check the string for any illegal characters.",
// .env file
DATABASE_URL="mongodb+srv://<USER>:<PASS>@cluster0.<ID>.mongodb.net/nuxt-app"
// schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
username String @unique
password String
}
// users.js
import { prisma } from ".";
export const createUser = (userData) => {
return prisma.user.create({
data: UserData
})
}
i am using
"nuxt": "^3.2.3"
"prisma": "^4.11.0"
the string is probably missing a collection name
DATABASE_URL="mongodb+srv://<user>:<pass>@<cluster_name>/<colection_name>?retryWrites=true&w=majority"