-
Notifications
You must be signed in to change notification settings - Fork 2
/
db.js
35 lines (33 loc) · 910 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
24
25
26
27
28
29
30
31
32
33
34
35
const mongoose = require('mongoose');
module.exports = {
connect: DB_HOST => {
mongoose.set('useNewUrlParser', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);
mongoose.set('useCreateIndex', true);
mongoose.set('useUnifiedTopology', true);
mongoose
.connect(DB_HOST)
.then(() => {
console.log('Database connection successful ');
})
.catch(reason => {
console.error(reason);
console.log(
'MongoDB connection error. Please make sure MongoDB is running'
);
process.exit();
});
},
close: () => {
mongoose.connection
.close()
.then(data => {
console.log('Database connection closed successfully ');
})
.catch(reason => {
console.error(reason);
console.log('Database connection cannot be closed ');
});
}
};