3 const MongoClient
= require('mongodb');
4 const fs
= require('fs');
6 // This script deletes charging stations
7 // Filter charging stations by id pattern
9 // Use Case: ev-simulator creates thousands of charging stations, which are not longer needed.
10 // Delete these charging stations all at once
13 const config
= JSON
.parse(fs
.readFileSync('scriptConfig.json', 'utf8'));
15 // Mongo Connection and Query
16 if (config
&& config
.mongoConnectionString
) {
17 MongoClient
.connect(config
.mongoConnectionString
, async
function(err
, client
) {
18 const db
= client
.db();
20 for await (const tenantID
of config
.tenantIDs
) {
21 const response
= await db
.collection(tenantID
+ '.chargingstations').deleteMany(
22 { _id
: { '$regex': config
.idPattern
} }
24 console
.log(response
.deletedCount
, `Charging Stations with id = %${config.idPattern}% deleted. TenantID =`, tenantID
);