-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
23 lines (23 loc) · 826 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require('dotenv').config();
var mongoose = require('mongoose');
//options for db connection
const options = {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
};
mongoose.connect(process.env.DB_URI, options)
.then(() => {
console.log('Connected to DB on Mongo Atlas.');
console.log(`Mongoose says: ${mongoose.connection.readyState}`);
console.log(`DB name:${mongoose.connection.db.databaseName}`);
// console.log(`Collections Available:`);
// console.log(mongoose.connection.db.listCollections({},{ nameOnly: true }));
})
.catch(err => {
console.log('Db connection error=======');
console.log(err);
//optional
alert('Terminator Server!');
process.exit(1); //force to terminate the program.
})