Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mongo/Mongoose will not pass a string

Attempting to connect to MongoDB via a follow-along, and I keep getting this error:

The uri parameter to openUri() must be a string, got "undefined". Make sure the first parameter to mongoose.connect() or mongoose.createConnection() is a string.

Here is the code I’m working with:
.env file (I changed the username and password. The name is cluster0)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

MONGO_URI="mongodb+srv://username:password@cluster0.l94wepe.mongodb.net/?retryWrites=true&w=majority"

Server.js

dotenv.config();

mongoose
  .connect(process.env.MONGODB_URI)

  .then(() => {
    console.log("connected to db");
  })
  .catch((err) => {
    console.log(err.message);
  });

Any help is appreciated, let me know what other info I can provide. Thank you.

>Solution :

The .env file has "MONGO_URI" and the JS file has "MONGODB_URI"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading