-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.js
45 lines (31 loc) · 980 Bytes
/
database.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
40
41
42
43
44
45
const { MongoClient } = require("mongodb");
const client = new MongoClient(process.env.MONGO_CONN_STR);
async function write(albums) {
try {
await client.connect();
const announced = client.db("RapPremiery").collection("announced");
for(const album of albums){
await announced.insertOne({name: album.name, artist: album.artists[0].name});
}
} finally {
await client.close();
}
}
async function find(albums) {
try {
await client.connect();
const announced = client.db("RapPremiery").collection("announced");
let foundAlbums = [];
for(const album of albums){
const response = await announced.findOne({name: album.name, artist: album.artists[0].name});
if(response != null){
foundAlbums.push(album);
}
}
return foundAlbums;
} finally {
await client.close();
}
}
module.exports.write = write;
module.exports.find = find;