Vue UI + UI server
[e-mobility-charging-stations-simulator.git] / src / scripts / deleteChargingStations.js
CommitLineData
5c38ecb0
JB
1#!/usr/bin/env node
2
68d2797d 3const fs = require('fs');
e8bdfa71 4
8114d10e
JB
5const MongoClient = require('mongodb');
6
e8bdfa71
J
7// This script deletes charging stations
8// Filter charging stations by id pattern
9
7f774a55 10// Use Case: e-mobility-charging-stations-simulator creates thousands of charging stations, which are not longer needed.
e8bdfa71
J
11// Delete these charging stations all at once
12
13// Config
5fdab605 14const config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8'));
e8bdfa71
J
15
16// Mongo Connection and Query
eaa20d18 17if (config && config.mongoConnectionString) {
e7aeea18 18 MongoClient.connect(config.mongoConnectionString, async function (err, client) {
eaa20d18 19 const db = client.db();
e8bdfa71
J
20
21 for await (const tenantID of config.tenantIDs) {
e7aeea18
JB
22 const response = await db
23 .collection(tenantID + '.chargingstations')
24 .deleteMany({ _id: { $regex: config.idPattern } });
32de5a57 25 console.info(
e7aeea18
JB
26 response.deletedCount,
27 `Charging Stations with id = %${config.idPattern}% deleted. TenantID =`,
28 tenantID
e8bdfa71 29 );
e8bdfa71
J
30 }
31 client.close();
32 });
33}