monkeytype/backend/init/mongodb.js

23 lines
446 B
JavaScript
Raw Normal View History

2021-06-07 00:32:37 +08:00
const { MongoClient } = require("mongodb");
let mongoClient;
module.exports = {
async connectDB() {
return MongoClient.connect(process.env.DB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then((client) => {
mongoClient = client;
})
.catch((e) => {
console.log(e);
process.exit(1);
});
},
mongoDB() {
return mongoClient.db(process.env.DB_NAME);
},
};