forked from InbarTakdim/SMARTPARK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbconf.js
26 lines (23 loc) · 828 Bytes
/
dbconf.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
//Connect to MongoDB on mLab via Mongoose
var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
var config = {
mongoUrl: 'mongodb://db_usr:[email protected]:55961/smartparkapp'
}
console.log('connecting...');
//The server option auto_reconnect is defaulted to true
var options = {
server: {
auto_reconnect: true,
}
};
mongoose.connect(config.mongoUrl, options);
db = mongoose.connection; // NOTE: a global connection variable
// Events handlers for Mongoose
db.on('error', err => console.log(`Mongoose: Error: ${err}`));
db.on('open', () => console.log(`Mongoose: Connection established`));
db.on('disconnected', () => {
console.log('Mongoose: Connection stopped, recconect');
mongoose.connect(config.mongoUrl, options);
});
db.on('reconnected', () => console.info('Mongoose reconnected!'));