README.md: refinement
[e-mobility-charging-stations-simulator.git] / src / scripts / setCSPublicFlag.js
CommitLineData
5c38ecb0
JB
1#!/usr/bin/env node
2
68d2797d
JB
3const MongoClient = require('mongodb');
4const 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 14const config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8'));
e8bdfa71
J
15
16// Mongo Connection and Query
eaa20d18 17if (config && config.mongoConnectionString) {
e8bdfa71
J
18 MongoClient.connect(config.mongoConnectionString, {
19 useUnifiedTopology: true,
20 useNewUrlParser: true
5fdab605 21 }, async function(err, client) {
eaa20d18 22 const db = client.db();
e8bdfa71
J
23
24 for await (const tenantID of config.tenantIDs) {
5fdab605
JB
25 const response = await db.collection(tenantID + '.chargingstations').updateMany(
26 { _id: { '$regex': config.idPattern } },
27 { $set: { public: config.publicFlag } }
e8bdfa71
J
28 );
29 console.log(response.modifiedCount, `Charging Stations with id = %${config.idPattern}% updated. TenantID =`, tenantID);
30 }
31 client.close();
32 });
33}