-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongoConnection.js
32 lines (24 loc) · 913 Bytes
/
mongoConnection.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
const mongoose = require('mongoose');
const config = require('./config');
const setupMongooseConnections = function() {
mongoose.Promise = global.Promise;
// mongoose.set('debug', true);
mongoose.connect(config.MONGO.MONGO_URL);
// mongoose.connect("mongodb://dbuser:dbuser@ds245287.mlab.com:45287/samplemlab");
mongoose.connection.on('connected', function() {
console.log('Mongoose is now connected to ', config.MONGO.MONGO_URL);
});
mongoose.connection.on('error', function(err) {
console.error('Error in Mongoose connection: ', err);
});
mongoose.connection.on('disconnected', function() {
console.log('Mongoose is now disconnected..!');
});
process.on('SIGINT', function() {
mongoose.connection.close(function() {
console.log('Mongoose disconnected on process termination');
process.exit(0);
});
});
}
module.exports = setupMongooseConnections;