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