2023-11-01 02:00:36 +00:00
|
|
|
const mongodb = require('mongodb');
|
|
|
|
|
|
|
|
const MongoClient = mongodb.MongoClient;
|
|
|
|
|
|
|
|
let database;
|
|
|
|
|
|
|
|
async function connectToDatabase() {
|
2023-11-04 12:21:51 +00:00
|
|
|
const client = await MongoClient.connect('mongodb://0.0.0.0:27017')
|
2023-11-01 20:03:07 +00:00
|
|
|
database = client.db('BDE');
|
2023-11-01 02:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getDb() {
|
|
|
|
if (!database) {
|
|
|
|
throw { message: 'You must connect first!' };
|
|
|
|
}
|
|
|
|
return database;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
connectToDatabase: connectToDatabase,
|
|
|
|
getDb: getDb,
|
|
|
|
};
|