-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.js
39 lines (34 loc) · 974 Bytes
/
connection.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
const development = require("./env/development.js");
const production = require("./env/production.js");
const mongoose = require('mongoose');
const URI = production.MONGO_URI || development.MONGO_URI;
const Grid = require('gridfs-stream');
mongoose.Promise = require('bluebird');
module.exports = function connection(app, cb) {
let connection;
let options = {
server: {
socketOptions: {
keepAlive: 300000, connectTimeoutMS: 30000
}
},
replset: {
socketOptions: {
keepAlive: 300000,
connectTimeoutMS : 30000
}
}
};
if(production.MONGO_URI) {
connection = mongoose.connect(URI, options);
} else {
connection = mongoose.connect(URI);
}
if(development.collectionsDrop) {
mongoose.connection.dropDatabase();
};
mongoose.connection.once('open', function() {
mongoose.gfs = Grid(mongoose.connection.db, mongoose.mongo);
cb(null, mongoose);
});
};