const mongoose = require('mongoose');
const connectDB = async () => {
mongoose
.connect('mongodb://localhost:27017/playground', {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
})
.then(() => console.log('Connected Successfully'))
.catch((err) => console.error('Not Connected'));
}
module.exports = connectDB;
const mongoose = require("mongoose");
// database connection with mongoose
mongoose.connect("mongodb://localhost/todos", {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log("connection successful"))
.catch((err) => console.log(err));
const conn = mongoose.createConnection('mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]', options);