1 const { MongoClient } = require('mongodb')
2 const fs = require('node:fs')
4 // This script deletes charging stations
5 // Filter charging stations by id pattern
7 // Use Case: e-mobility-charging-stations-simulator creates thousands of charging stations, which are not longer needed.
8 // Delete these charging stations all at once
11 const config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8'))
13 // Mongo Connection and Query
14 if (config?.mongoConnectionString) {
15 MongoClient.connect(config.mongoConnectionString, async (_err, client) => {
16 const db = client.db()
18 for await (const tenantID of config.tenantIDs) {
19 const response = await db
20 .collection(`${tenantID}.chargingstations`)
21 .deleteMany({ _id: { $regex: config.idPattern } })
23 response.deletedCount,
24 `Charging Stations with id = %${config.idPattern}% deleted. TenantID =`,