1const mongoose = require('mongoose');
2
3const connectDB = async () => {
4 mongoose
5 .connect('mongodb://localhost:27017/playground', {
6 useCreateIndex: true,
7 useNewUrlParser: true,
8 useUnifiedTopology: true,
9 useFindAndModify: false
10 })
11 .then(() => console.log('Connected Successfully'))
12 .catch((err) => console.error('Not Connected'));
13}
14
15module.exports = connectDB;
1mongoose.connect('mongodb://localhost:27017/test', {
2 useMongoClient: true,
3 connectTimeoutMS: 1000
4})
1mongoose.connect('mongodb://username:password@host:port/database?options...', {useNewUrlParser: true});