Add Insomnia UI protocol collection
[e-mobility-charging-stations-simulator.git] / src / scripts / deleteChargingStations.js
index 3ebeb0942a1d007a18db7324cc12504088639816..f92cdcf1a7ea0d9573185af3a174a7f161d7108d 100755 (executable)
@@ -1,12 +1,13 @@
 #!/usr/bin/env node
 
-const MongoClient = require('mongodb');
 const fs = require('fs');
 
+const MongoClient = require('mongodb');
+
 // This script deletes charging stations
 // Filter charging stations by id pattern
 
-// Use Case: charging-stations-simulator creates thousands of charging stations, which are not longer needed.
+// Use Case: e-mobility-charging-stations-simulator creates thousands of charging stations, which are not longer needed.
 // Delete these charging stations all at once
 
 // Config
@@ -14,14 +15,18 @@ const config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8'));
 
 // Mongo Connection and Query
 if (config && config.mongoConnectionString) {
-  MongoClient.connect(config.mongoConnectionString, async function(err, client) {
+  MongoClient.connect(config.mongoConnectionString, async function (err, client) {
     const db = client.db();
 
     for await (const tenantID of config.tenantIDs) {
-      const response = await db.collection(tenantID + '.chargingstations').deleteMany(
-        { _id: { '$regex': config.idPattern } }
+      const response = await db
+        .collection(tenantID + '.chargingstations')
+        .deleteMany({ _id: { $regex: config.idPattern } });
+      console.info(
+        response.deletedCount,
+        `Charging Stations with id = %${config.idPattern}% deleted. TenantID =`,
+        tenantID
       );
-      console.log(response.deletedCount, `Charging Stations with id = %${config.idPattern}% deleted. TenantID =`, tenantID);
     }
     client.close();
   });