-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbHelper.js
39 lines (32 loc) · 991 Bytes
/
dbHelper.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
39
const MongoClient = require('mongodb').MongoClient
const mongoClientOptions = { useUnifiedTopology: true, useNewUrlParser: true }
const uri = 'mongodb+srv://ukel-user-20:[email protected]/sprinklr_db?retryWrites=true&w=majority'
const dbName = 'sprinklr_db'
var db = undefined
module.exports.connect = async () => {
try {
let client = await MongoClient.connect(uri, mongoClientOptions);
db = client.db(dbName)
}
catch (error) {
console.log(error)
throw new Error(error)
}
}
module.exports.insertGroup = async (groupId) => {
if (!db) {
throw new Error('No connection to database');
}
db.collection("groups").insertOne({"groupId": groupId}, function(err, res) {
if (err)
throw err
console.log("1 document inserted")
});
}
module.exports.getGroups = async () => {
if (!db) {
throw new Error('No connection to database');
}
let res = await db.collection("groups").find({}).toArray()
return res
}