f92cdcf1a7ea0d9573185af3a174a7f161d7108d
3 const fs
= require('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
&& config
.mongoConnectionString
) {
18 MongoClient
.connect(config
.mongoConnectionString
, async
function (err
, client
) {
19 const db
= client
.db();
21 for await (const tenantID
of config
.tenantIDs
) {
22 const response
= await db
23 .collection(tenantID
+ '.chargingstations')
24 .deleteMany({ _id
: { $regex
: config
.idPattern
} });
26 response
.deletedCount
,
27 `Charging Stations with id = %${config.idPattern}% deleted. TenantID =`,