I have tried tons of different codes… this is just one of them…
const mongoose = require("mongoose");
const connection =
"mongodb+srv://<myusernamehere>:<mypasswordhere>@cluster0.gcyyo.mongodb.net/<mydatabasehere>?retryWrites=true&w=majority";
mongoose
.connect(connection, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
.then(() => console.log("Database Connected Successfully"))
.catch((err) => console.log(err));