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