Issue
This Content is from Stack Overflow. Question asked by user3226932
can’t connect to mongodb server when using env var in mongodb + prisma + nextjs application. getting this error error: Error validating datasource db: the URL must start with the protocol mongo.
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
.env: DATABASE_URL=mongodb+srv://username:password@somemongodbserver/mydb?retryWrites=true&w=majority
.env.local: DATABASE_URL=mongodb+srv://username:password@somemongodbserver/mydb?retryWrites=true&w=majority
Also tried putting this in next.config.js
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
env: {
DATABASE_URL: process.env.DATABASE_URL,
},
};
Solution
turns out I already I had DATABASE_URL
env var set locally for Postgres and it was being used, changing the env var name in the nextjs app fixed the issue
This Question was asked in StackOverflow by user3226932 and Answered by user3226932 It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.