-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmongoClient.js
47 lines (39 loc) · 1.44 KB
/
mongoClient.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
43
44
45
46
47
/*
Mongo connection information
*/
/*
This program is free software. It comes without any warranty, and is offered “as-is”, without warranty. The software user accepts all liability for damages resulting in the use of this software.
All trademarks are the property of their respective owners.
No agreement has been made between any party to ensure support of this project. Any connectivity issues should be investigated with your authorized support representative.
To the extent permitted by applicable law.
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
See LICENSE file for more information.
*/
require(`dotenv`).config();
const assert = require(`assert`),
mongoClient = require(`mongodb`).MongoClient;
var mongoDB = {};
function connect(callback){
if(process.env.MONGO_USER != `` && process.env.MONGO_PASSWORD != ``){
var mongoURL = process.env.MONGO_URL.replace(/<username>/, process.env.MONGO_USER)
mongoURL = mongoURL.replace(/<password>/, process.env.MONGO_PASSWORD)
} else {
var mongoURL = process.env.MONGO_URL.replace(/<username>:<password>@/, process.env.MONGO_USER)
}
mongoClient.connect(mongoURL, { 'useNewUrlParser': true, 'useUnifiedTopology': true }, (err, db) => {
mongoDB = db;
callback();
});
}
function get(){
return mongoDB;
}
function close(){
mongoDB.close();
}
module.exports = {
connect,
get,
close
};