-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.js
35 lines (28 loc) · 811 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
'use strict';
const mongoose = require('mongoose');
require('dotenv').config();
const dbURI = process.env.MONGO_URI || 'mongodb://localhost/test_roles';
const options = {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true
};
// Create the database connection
mongoose.connect(dbURI, options, err => {
if (err) {
console.log('DB Error: ', err);
throw err;
} else {
console.log('MongoDB Connected');
}
});
mongoose.connection.on('connected', function () {
console.log('Mongoose default connection open to ' + dbURI);
});
mongoose.connection.on('error', function (err) {
console.log('Mongoose default connection error: ' + err);
});
mongoose.connection.on('disconnected', function () {
console.log('Mongoose default connection disconnected');
});