Commit | Line | Data |
---|---|---|
66a7748d | 1 | const { MongoClient } = require('mongodb') |
0749233f | 2 | const fs = require('node:fs') |
8114d10e | 3 | |
e8bdfa71 J |
4 | // This script deletes charging stations |
5 | // Filter charging stations by id pattern | |
6 | ||
7f774a55 | 7 | // Use Case: e-mobility-charging-stations-simulator creates thousands of charging stations, which are not longer needed. |
e8bdfa71 J |
8 | // Delete these charging stations all at once |
9 | ||
10 | // Config | |
66a7748d | 11 | const config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8')) |
e8bdfa71 J |
12 | |
13 | // Mongo Connection and Query | |
acd36c7a | 14 | if (config?.mongoConnectionString) { |
48847bc0 | 15 | MongoClient.connect(config.mongoConnectionString, async (_err, client) => { |
66a7748d | 16 | const db = client.db() |
e8bdfa71 J |
17 | |
18 | for await (const tenantID of config.tenantIDs) { | |
e7aeea18 | 19 | const response = await db |
14ecae6a | 20 | .collection(`${tenantID}.chargingstations`) |
66a7748d | 21 | .deleteMany({ _id: { $regex: config.idPattern } }) |
32de5a57 | 22 | console.info( |
e7aeea18 JB |
23 | response.deletedCount, |
24 | `Charging Stations with id = %${config.idPattern}% deleted. TenantID =`, | |
66a7748d JB |
25 | tenantID |
26 | ) | |
e8bdfa71 | 27 | } |
66a7748d JB |
28 | client.close() |
29 | }) | |
e8bdfa71 | 30 | } |