| 1 | const fs = require('node:fs') |
| 2 | |
| 3 | const { MongoClient } = require('mongodb') |
| 4 | |
| 5 | // This script sets charging stations public or private |
| 6 | // Filter charging stations by id pattern |
| 7 | |
| 8 | // Use case: simulate charging station for roaming tests |
| 9 | // charging stations are private by default |
| 10 | // set public = true |
| 11 | |
| 12 | // Config |
| 13 | const config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8')) |
| 14 | |
| 15 | // Mongo Connection and Query |
| 16 | if (config?.mongoConnectionString) { |
| 17 | // eslint-disable-next-line n/handle-callback-err |
| 18 | MongoClient.connect(config.mongoConnectionString, async (_err, client) => { |
| 19 | const db = client.db() |
| 20 | |
| 21 | for await (const tenantID of config.tenantIDs) { |
| 22 | const response = await db |
| 23 | .collection(`${tenantID}.chargingstations`) |
| 24 | .updateMany({ _id: { $regex: config.idPattern } }, { $set: { public: config.publicFlag } }) |
| 25 | console.info( |
| 26 | response.modifiedCount, |
| 27 | `Charging Stations with id = %${config.idPattern}% updated. TenantID =`, |
| 28 | tenantID |
| 29 | ) |
| 30 | } |
| 31 | client.close() |
| 32 | }) |
| 33 | } |