From b7902a569e0814525f5de22e543bedb8947e06c7 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Wed, 21 Apr 2021 23:20:32 +0300 Subject: [PATCH] migration to fix null values instead of array of events --- migration.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/migration.js b/migration.js index fae73c1..2378c93 100644 --- a/migration.js +++ b/migration.js @@ -38,8 +38,21 @@ async function addDebugInfoStatus() { } } +async function fixNullEvents() { + 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.events == null) { + await collection.updateOne({ number: vehicle.number }, { $set: { events: [] } }); + } + } +} + (async () => { //await addUpdatedDate(); - await addDebugInfoStatus(); + //await addDebugInfoStatus(); + await fixNullEvents(); console.log('====== Done ======'); })(); \ No newline at end of file