Commit | Line | Data |
---|---|---|
5fdab605 JB |
1 | import MongoClient from 'mongodb'; |
2 | import fs from 'fs'; | |
e8bdfa71 J |
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 | |
5fdab605 | 11 | const config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8')); |
e8bdfa71 J |
12 | |
13 | // Mongo Connection and Query | |
36a16ec2 | 14 | if (config?.mongoConnectionString) { |
e8bdfa71 J |
15 | MongoClient.connect(config.mongoConnectionString, { |
16 | useUnifiedTopology: true, | |
17 | useNewUrlParser: true | |
5fdab605 | 18 | }, async function(err, client) { |
e8bdfa71 J |
19 | const db = client.db('evse'); |
20 | ||
21 | for await (const tenantID of config.tenantIDs) { | |
5fdab605 JB |
22 | const response = await db.collection(tenantID + '.chargingstations').deleteMany( |
23 | { _id: { '$regex': config.idPattern } } | |
e8bdfa71 J |
24 | ); |
25 | console.log(response.deletedCount, `Charging Stations with id = %${config.idPattern}% deleted. TenantID =`, tenantID); | |
26 | } | |
27 | client.close(); | |
28 | }); | |
29 | } |