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