scripts to set CS public or delete CS
[e-mobility-charging-stations-simulator.git] / src / scripts / deleteChargingStations.ts
1 var MongoClient = require('mongodb');
2 var fs = require('fs');
3
4 // This script deletes charging stations
5 // Filter charging stations by id pattern
6
7 // Use Case: ev-simulator creates thousands of charging stations, which are not longer needed.
8 // Delete these charging stations all at once
9
10 // Config
11 var config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8'));
12
13 // Mongo Connection and Query
14 if (config && config.mongoConnectionString) {
15 MongoClient.connect(config.mongoConnectionString, {
16 useUnifiedTopology: true,
17 useNewUrlParser: true
18 }, async function(err, client) {
19 const db = client.db('evse');
20
21 for await (const tenantID of config.tenantIDs) {
22 let response = await db.collection(tenantID + '.chargingstations').deleteMany(
23 { _id: {'$regex': config.idPattern} }
24 );
25 console.log(response.deletedCount, `Charging Stations with id = %${config.idPattern}% deleted. TenantID =`, tenantID);
26 }
27 client.close();
28 });
29 }