From 0d1bce9b67bb212c7fcc4856b4d2884467d9cad4 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Sun, 31 Jan 2021 16:18:47 +0300 Subject: [PATCH] Migration for adding status to debugInfo --- migration.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/migration.js b/migration.js index 127ec59..fae73c1 100644 --- a/migration.js +++ b/migration.js @@ -21,7 +21,25 @@ async function addUpdatedDate() { } } +async function addDebugInfoStatus() { + let client = await MongoClient.connect(process.env.MONGO_CONNECTION_STRING, { useUnifiedTopology: true }); + let db = client.db('autocatdev'); + let collection = db.collection('vehicles'); + let vehicles = await collection.find().toArray(); + for(let vehicle of vehicles) { + if(vehicle.debugInfo) { + for(const [providerName] of Object.entries(vehicle.debugInfo)) { + if(vehicle.debugInfo[providerName]) { + vehicle.debugInfo[providerName].status = vehicle.debugInfo[providerName].error == null ? 0 : 1; + } + } + await collection.updateOne({ _id: vehicle._id }, { $set: { debugInfo: vehicle.debugInfo } }); + } + } +} + (async () => { - await addUpdatedDate(); + //await addUpdatedDate(); + await addDebugInfoStatus(); console.log('====== Done ======'); })(); \ No newline at end of file