mongoDB database url environment variable not found

i am new to mongoDB and trying to connect to mongoDB server.

the error:

npx prisma db push Environment variables loaded from .env 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 : 5.2.0

.env file


schema.prisma file

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

I’ve tried

  • creating new user names and passwords for mongoDB.
  • added my current IP address and the
  • double checking that the url is correct (copied from mongoDB).
  • double checking that the package.json matches the tutorial i am following.

Hi @Nicholas_Nelson,

I believe the error is for Prisma and not for any connection failures to a MongoDB instance based off my interpretation of the error:

Error code: P1012 error: Environment variable not found: DATABASE_URL

Have you tried raising this with prisma support regarding this? My guess is there should be some guides on how to connect to an Atlas instance using prisma.

An additional note, for troubleshooting purposes, you can try connecting without environment variables as a to see if you’re able to connect to a MongoDB instance.


If you’re encountering the issue where the MongoDB database URL environment variable is not found, it’s likely due to an issue with how the environment variables are being set or accessed in your application. Here are some steps you can take to troubleshoot and resolve the issue:

  1. Check Environment Variable Name: Make sure that you are using the correct environment variable name to access the MongoDB database URL. Ensure that there are no typos or discrepancies in the variable name.
  2. Set Environment Variable: If you haven’t set the environment variable yet, make sure you set it with the correct value. Depending on your application and environment, you might set the environment variable in different ways:
  • If you are running your application locally, you can set the environment variable in your development environment’s configuration files.
  • If you are deploying your application to a server, ensure that the environment variable is set in the server’s environment.
  1. Restart Your Application: After setting the environment variable, restart your application. Environment variables are typically loaded when the application starts, so a restart is necessary for the changes to take effect.
  2. Use the Correct Syntax to Access the Variable: Depending on the programming language or framework you are using, the syntax to access environment variables might differ. For example:
  • In Node.js with the process.env object: process.env.MONGODB_URL
  • In Python with os module: os.environ['MONGODB_URL']
  • In Java with System class: System.getenv("MONGODB_URL")
  1. Check Application Configuration: Verify that your application’s configuration or settings are correctly referencing the environment variable for the MongoDB database URL. Any discrepancy here could lead to the variable not being found.
  2. Check for Typos: Double-check for any typos or mistakes in the environment variable name. Even a minor typo can prevent the variable from being accessed.
  3. Debugging and Logging: Implement logging or debug statements in your code to print out the value of the environment variable at various stages of your application’s execution. This can help you pinpoint where the issue is occurring.
  4. Review Deployment Process: If the error is occurring in a deployed environment, review your deployment process to ensure that environment variables are properly set in the production environment.
  5. Consult Documentation: Refer to the documentation of the programming language, framework, or hosting platform you are using. It often provides guidance on setting and accessing environment variables.
  6. Ask for Help: If you’re still facing issues, consider seeking help from relevant forums, communities, or developer support for the specific technology stack you are using.

Remember that the exact steps might vary based on your application’s architecture and the programming language/framework you’re using. By following these general steps and paying attention to your application’s specific setup, you should be able to resolve the issue of the MongoDB database URL environment variable not being found.

Thanks to ChatGPT for this very generic answer.