1 import MongoClient from
'mongodb';
4 // This script sets charging stations public or private
5 // Filter charging stations by id pattern
7 // Use case: simulate charging station for roaming tests
8 // charging stations are private by default
12 const config
= JSON
.parse(fs
.readFileSync('scriptConfig.json', 'utf8'));
14 // Mongo Connection and Query
15 if (config
&& config
.mongoConnectionString
) {
16 MongoClient
.connect(config
.mongoConnectionString
, {
17 useUnifiedTopology
: true,
19 }, async function(err
, client
) {
20 const db
= client
.db('evse');
22 for await (const tenantID
of config
.tenantIDs
) {
23 const response
= await db
.collection(tenantID
+ '.chargingstations').updateMany(
24 { _id
: { '$regex': config
.idPattern
} },
25 { $set
: { public: config
.publicFlag
} }
27 console
.log(response
.modifiedCount
, `Charging Stations with id = %${config.idPattern}% updated. TenantID =`, tenantID
);