-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.js
53 lines (46 loc) · 1.43 KB
/
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
46
47
48
49
50
51
52
53
const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb://database:27017";
const client = new MongoClient(uri);
const connection = client.connect();
exports.clear_authorities = function () {
return connection.then(() => {
const db = client.db('plzTool');
const coll = db.collection('authorities');
return coll.deleteMany();
});
};
exports.clear_cities = function () {
return connection.then(() => {
const db = client.db('plzTool');
const coll = db.collection('cities');
return coll.deleteMany();
});
};
exports.find_authority_by_id = function (id) {
return connection.then(() => {
const db = client.db('plzTool');
const coll = db.collection('authorities');
return coll.findOne({id: id});
});
};
exports.find_city_by_plz = function (plz) {
return connection.then(() => {
const db = client.db('plzTool');
const coll = db.collection('cities');
return coll.findOne({PLZ: plz});
});
};
exports.add_authority = function (authority) {
return connection.then(() => {
const db = client.db('plzTool');
const coll = db.collection('authorities');
return coll.insertOne(authority);
});
};
exports.add_city = function (city) {
return connection.then(() => {
const db = client.db('plzTool');
const coll = db.collection('cities');
return coll.insertOne(city);
});
};