-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.js
42 lines (33 loc) · 856 Bytes
/
Database.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
const MongoClient = require("mongodb").MongoClient;
const option = {
auto_reconnect: true,
poolSize: 5,
ssl: false,
connectTimeoutMS: 1000,
socketTimeoutMS: 1000,
keepAlive: 3600000
};
let pool_db;
function MongoPool() {
}
function initPool(callback) {
MongoClient.connect(process.env.MONGO_CONNECTION, option, (err, db) => {
if (err) throw err;
console.log("Connected asd");
pool_db = db;
if (callback && typeof (callback) == "function")
callback(pool_db);
});
return MongoPool;
}
MongoPool.initPool = initPool;
function getInstance(callback) {
if (!pool_db) {
initPool(callback);
} else {
if (callback && typeof (callback) == "function")
callback(pool_db);
}
}
MongoPool.getInstance = getInstance;
module.exports = MongoPool;