Mongodb env variables

I want to connect to an atlas database and I created a Secret for the connection string.

Do I need to change anything in my Prisma schema file to use this variable in the repl? Prior threads I researched about this has not made this clear. Gratias tibi ago!

// 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"
}

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

Yep as I thought this would not work:

npx prisma db push
Prisma schema loaded from prisma/schema.prisma
Datasource "db": MongoDB database

Error: Prisma schema validation - (get-config wasm)
Error code: P1012
error: Environment variable not found: DATABASE_URL.
  -->  schema.prisma:10
   | 
 9 |   provider = "mongodb"
10 |   url      = env("DATABASE_URL")
   | 

Validation Error Count: 1
[Context: getConfig]

Prisma CLI Version : 4.14.1```

Did you make sure you clicked “save” on the secret and that the name is the same? Try running echo $DATABASE_URL in the shell and see if it returns your secret.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.