-
Notifications
You must be signed in to change notification settings - Fork 7
/
db.js
39 lines (31 loc) · 908 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
36
37
38
39
var mongoose = require('mongoose');
const config = require('./config/dev');
const DB_URL = config.database;
mongoose.Promise = require('bluebird');
/**
* Comment the auth/user/pass if your db requires no auth
*/
var options = {
useMongoClient: true,
// auth: { authdb: 'CrowdJigsaw' },
// user: config.user,
// pass: config.pass
};
mongoose.connect(DB_URL, options);
const db = mongoose.connection;
// const User = require('../models/user.js');
db.on('error', function (err) {
db.close();
console.log('[DB] Mongoose connection error: ' + err);
});
db.once('open', function () {
console.log('[DB] Mongoose connecting to ' + DB_URL);
});
db.on('connected', function () {
console.log('[DB] Mongoose connected to ' + DB_URL);
});
db.on('disconnected', function () {
db.close()
console.log('[DB] Mongoose connection disconnected');
});
module.exports = mongoose;