1const mongoAtlasUri =
2 "mongodb+srv://username@gmail.com:password@cluster0.mkb94.mongodb.net/DB_NAme?retryWrites=true&w=majority";
3
4try {
5 // Connect to the MongoDB cluster
6 mongoose.connect(
7 mongoAtlasUri,
8 { useNewUrlParser: true, useUnifiedTopology: true },
9 () => console.log(" Mongoose is connected")
10 );
11} catch (e) {
12 console.log("could not connect");
13}
1// local conecation
2
3const mongoose = require("mongoose");
4
5mongoose
6 .connect("mongodb://localhost:27017/testdb")
7 .then(() => console.log("Connected to MongoDB..."))
8 .catch((err) => console.error("Could not connect to MongoDB...", err));
9
1mongoose.connect('mongodb://username:password@host:port/database?options...', {useNewUrlParser: true});