-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
46 lines (34 loc) · 1.15 KB
/
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
36
37
38
39
40
41
42
43
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
const DB_URI = process.env.DB_URI
module.exports = (cb) => {
mongoose.set('debug', true);
let options = {
bufferMaxEntries: 0,
autoReconnect: true,
reconnectTries: 1
};
console.log("Connecting to mongo with options", options);
mongoose.connect(DB_URI, options, () => {
require('./models/user')
cb && cb()
});
mongoose.connection.on('connected', function () {
console.log('Mongoose default connection open to ' + DB_URI);
});
mongoose.connection.once('open', () => {
console.log('Connected to mongodb!');
});
mongoose.connection.on('error', function (err) {
console.error('Mongoose default connection error: ' + err);
});
mongoose.connection.on('disconnected', function () {
console.log('Mongoose default connection disconnected');
});
process.on('SIGINT', function () {
mongoose.connection.close(function () {
console.log('Mongoose default connection disconnected through app termination');
process.exit(0);
});
});
};