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