Commit | Line | Data |
---|---|---|
5c38ecb0 JB |
1 | #!/usr/bin/env node |
2 | ||
68d2797d JB |
3 | const MongoClient = require('mongodb'); |
4 | const fs = require('fs'); | |
e8bdfa71 J |
5 | |
6 | // This script deletes charging stations | |
7 | // Filter charging stations by id pattern | |
8 | ||
7f774a55 | 9 | // Use Case: e-mobility-charging-stations-simulator creates thousands of charging stations, which are not longer needed. |
e8bdfa71 J |
10 | // Delete these charging stations all at once |
11 | ||
12 | // Config | |
5fdab605 | 13 | const config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8')); |
e8bdfa71 J |
14 | |
15 | // Mongo Connection and Query | |
eaa20d18 | 16 | if (config && config.mongoConnectionString) { |
e7aeea18 | 17 | MongoClient.connect(config.mongoConnectionString, async function (err, client) { |
eaa20d18 | 18 | const db = client.db(); |
e8bdfa71 J |
19 | |
20 | for await (const tenantID of config.tenantIDs) { | |
e7aeea18 JB |
21 | const response = await db |
22 | .collection(tenantID + '.chargingstations') | |
23 | .deleteMany({ _id: { $regex: config.idPattern } }); | |
24 | console.log( | |
25 | response.deletedCount, | |
26 | `Charging Stations with id = %${config.idPattern}% deleted. TenantID =`, | |
27 | tenantID | |
e8bdfa71 | 28 | ); |
e8bdfa71 J |
29 | } |
30 | client.close(); | |
31 | }); | |
32 | } |