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