Commit | Line | Data |
---|---|---|
66a7748d | 1 | const fs = require('node:fs') |
e8bdfa71 | 2 | |
66a7748d | 3 | const { MongoClient } = require('mongodb') |
8114d10e | 4 | |
e8bdfa71 J |
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 | |
66a7748d | 13 | const config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8')) |
e8bdfa71 J |
14 | |
15 | // Mongo Connection and Query | |
acd36c7a | 16 | if (config?.mongoConnectionString) { |
66a7748d | 17 | // eslint-disable-next-line n/handle-callback-err |
48847bc0 | 18 | MongoClient.connect(config.mongoConnectionString, async (_err, client) => { |
66a7748d | 19 | const db = client.db() |
e8bdfa71 J |
20 | |
21 | for await (const tenantID of config.tenantIDs) { | |
e7aeea18 | 22 | const response = await db |
14ecae6a | 23 | .collection(`${tenantID}.chargingstations`) |
66a7748d | 24 | .updateMany({ _id: { $regex: config.idPattern } }, { $set: { public: config.publicFlag } }) |
32de5a57 | 25 | console.info( |
e7aeea18 JB |
26 | response.modifiedCount, |
27 | `Charging Stations with id = %${config.idPattern}% updated. TenantID =`, | |
66a7748d JB |
28 | tenantID |
29 | ) | |
e8bdfa71 | 30 | } |
66a7748d JB |
31 | client.close() |
32 | }) | |
e8bdfa71 | 33 | } |