Commit | Line | Data |
---|---|---|
e8bdfa71 J |
1 | var MongoClient = require('mongodb'); |
2 | var fs = require('fs'); | |
3 | ||
4 | // This script sets charging stations public or private | |
5 | // Filter charging stations by id pattern | |
6 | ||
7 | // Use case: simulate charging station for roaming tests | |
8 | // charging stations are private by default | |
9 | // set public = true | |
10 | ||
11 | // Config | |
12 | var config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8')); | |
13 | ||
14 | // Mongo Connection and Query | |
15 | if (config && config.mongoConnectionString) { | |
16 | MongoClient.connect(config.mongoConnectionString, { | |
17 | useUnifiedTopology: true, | |
18 | useNewUrlParser: true | |
19 | }, async function(err, client) { | |
20 | const db = client.db('evse'); | |
21 | ||
22 | for await (const tenantID of config.tenantIDs) { | |
23 | let response = await db.collection(tenantID + '.chargingstations').updateMany( | |
24 | { _id: {'$regex': config.idPattern} }, | |
25 | { $set: { public : config.publicFlag } } | |
26 | ); | |
27 | console.log(response.modifiedCount, `Charging Stations with id = %${config.idPattern}% updated. TenantID =`, tenantID); | |
28 | } | |
29 | client.close(); | |
30 | }); | |
31 | } |