forked from jacktheboss220/WhatsAppBotMultiDevice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb.js
More file actions
30 lines (29 loc) · 1.21 KB
/
mongodb.js
File metadata and controls
30 lines (29 loc) · 1.21 KB
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
require('dotenv').config();
//-------------------------------------------------------------------------------------------------------------//
const { MongoClient, ServerApiVersion } = require('mongodb');
const uri = `${process.env.MONGODB_KEY}`;
//-------------------------------------------------------------------------------------------------------------//
const mdClient = new MongoClient(uri, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
}
});
//-------------------------------------------------------------------------------------------------------------/
(async () => {
let flag = false;
await mdClient.connect().then(() => { console.log("Connected to Database") }).catch(err => { console.log(err) });
const db = mdClient.db('MyBotDataDB');
const collection = await db.collections();
collection.forEach(ele => {
if (ele.namespace == "MyBotDataDB.AuthTable") {
flag = true;
}
});
if (flag == false) {
await db.createCollection("AuthTable");
}
})();
//-------------------------------------------------------------------------------------------------------------//
module.exports = mdClient;