3 const fs
= require('node:fs')
5 const { MongoClient
} = require('mongodb')
7 // This script deletes charging stations
8 // Filter charging stations by id pattern
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
14 const config
= JSON
.parse(fs
.readFileSync('scriptConfig.json', 'utf8'))
16 // Mongo Connection and Query
17 if (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()
22 for await (const tenantID
of config
.tenantIDs
) {
23 const response
= await db
24 .collection(`${tenantID}.chargingstations`)
25 .deleteMany({ _id
: { $regex
: config
.idPattern
} })
27 response
.deletedCount
,
28 `Charging Stations with id = %${config.idPattern}% deleted. TenantID =`,