Commit | Line | Data |
---|---|---|
5c38ecb0 JB |
1 | #!/usr/bin/env node |
2 | ||
68d2797d JB |
3 | const MongoClient = require('mongodb'); |
4 | const fs = require('fs'); | |
e8bdfa71 J |
5 | |
6 | // This script sets charging stations public or private | |
7 | // Filter charging stations by id pattern | |
8 | ||
9 | // Use case: simulate charging station for roaming tests | |
10 | // charging stations are private by default | |
11 | // set public = true | |
12 | ||
13 | // Config | |
5fdab605 | 14 | const config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8')); |
e8bdfa71 J |
15 | |
16 | // Mongo Connection and Query | |
eaa20d18 | 17 | if (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 | .updateMany({ _id: { $regex: config.idPattern } }, { $set: { public: config.publicFlag } }); | |
25 | console.log( | |
26 | response.modifiedCount, | |
27 | `Charging Stations with id = %${config.idPattern}% updated. TenantID =`, | |
28 | tenantID | |
e8bdfa71 | 29 | ); |
e8bdfa71 J |
30 | } |
31 | client.close(); | |
32 | }); | |
33 | } |