Hello,
I am very new to this. I first for the error of
Error: The
uri
parameter toopenUri()
must be a string, got “undefined”. Make sure the first parameter tomongoose.connect()
ormongoose.createConnection()
is a string.
but my conectDB was below dotenv. I saw someone saying ‘process.env.MONGO_URI’ should be in string so i did that, while the error disappeared, this new error is now here.
I have searched for some solutions but nothing seems to work.
MONGO_URI = 'mongodb+srv://user:password@cluster0.cdusxnp.mongodb.net/?retryWrites=true&w=majority'
const mongoose = require("mongoose");
const colors = require("colors");
const connectDB = async () => {
try {
const conn = await mongoose.connect("process.env.MONGO_URI", {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: true,
});
console.log(`MongoDB Connected: ${conn.connection.host}`.cyan.underline);
} catch (error) {
console.log(`Error: ${error.message}`.red.bold);
process.exit();
}
};
module.exports = connectDB;
Any help would be appreciated, as my presentation is tomorrow ^^