migration to fix null values instead of array of events

This commit is contained in:
Selim Mustafaev 2021-04-21 23:20:32 +03:00
parent bad9a810de
commit b7902a569e

View File

@ -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 ======');
})();