-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmongo.js
More file actions
35 lines (32 loc) · 803 Bytes
/
mongo.js
File metadata and controls
35 lines (32 loc) · 803 Bytes
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
const mongo = require("mongoose");
const config = require("./config");
const logger = require("./logger")();
const env = config["env"];
let uri = "";
if (config["isMongoUri"]) {
uri = config["mongo_uri"];
} else if (env === "production") {
uri = `mongodb://${config["mongo_username"]}:${config["mongo_password"]}@${
config["mongo_host"]
}:${config["mongo_port"]}/${config["mongo_dbname"]}`;
} else {
uri = `mongodb://${config["mongo_host"]}:${config["mongo_port"]}/${
config["mongo_dbname"]
}`;
}
mongo.connect(
uri,
{
useCreateIndex: true,
useNewUrlParser: true,
useFindAndModify: false
},
err => {
if (err) {
throw new Error("Error connecting mongoose");
} else {
logger.info("Connection successfull");
}
}
);
module.exports = mongo;