-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
38 lines (29 loc) · 843 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
const mongoose = require("mongoose");
const { saveAreas, savePosts } = require("./json/saveDB");
const { MONGO_ENDPOINT, STAGE } = process.env;
module.exports = async function createConnection() {
switch (STAGE) {
default: {
break;
}
case "development":
case "alpha": {
mongoose.set("debug", true);
break;
}
}
console.log("MongoDB connecting...");
const connection = await mongoose.connect(MONGO_ENDPOINT, {
dbName: "memona",
autoIndex: STAGE === "development",
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
console.log("MongoDB is connected with mongoose");
// await saveAreaData();
// console.log("complete saving area json datas");
// await savePosts();
// console.log("complete saving post datas");
return connection;
};