MONGODB_URI not found following Next.js App tutorial


I’m following this small tutorial to learn Next.js and MongoDB in detail. However, I’m encountering some issues with the following in this tutorial. I’m trying to use the .env.local.example from the file to the mongodb.js. I rechecked both of my Atlas clusters and connect it to the Compass. The compass shows all of the data and I can see the sample_mflix fine. My only issue is that it doesn’t show through the landing page. Thanks for your help :slight_smile:

this is the content of .env.local.example:


Welcome to the MongoDB community @Zeid_Tisnes!

Per the tutorial, make sure you rename or copy .env.local.example to .env.local after adding your configuration. Try renaming the file and restarting your Next.js app with npm run dev.


I did change the name to .env.local but still no luck with Authentication failed error message. Even though I have the same credentials. I’m a little bit lost and confused because it is literally what the tutorial shows.


Ok, apparently the URI I had initially was not working and I had to change it to this instead:


Hi @Zeid_Tisnes,

That sounds like progress … the MONGO_URI is set but the credentials aren’t correct yet.

There should be a line preceding the “ready” message indicating that the an env file is being read:

Loaded env from /home/alone/with-mongodb/.env.local

If there is an obvious problem with the format of MONGO_URI there should be an error after the “event - compiled successfully” message similar to:

MongoParseError: Invalid connection string

The error you encountered suggests the connection string format is correct, but could not be used to successfully authenticate to your MongoDB deployment.


Hi @Zeid_Tisnes, I hope it’s working now? Just a quick note that you should change your user on the Atlas database you shared. The connection string you added in your solution gives away your username and password combo, giving me and everyone else reading this full access to your database. Given it’s only a practice application, this isn’t a huge problem but in general you will want to anonymize the connection string to something like mongodb+srv://


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