Migration for converting null notes to empty array

This commit is contained in:
Selim Mustafaev 2022-03-25 18:44:14 +03:00
parent 6d57210b7e
commit fc5ec6d0bd

View File

@ -51,9 +51,22 @@ async function fixNullEvents() {
} }
} }
async function fixNullNotes() {
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.notes == null) {
//console.log(vehicle.events);
await collection.updateOne({ number: vehicle.number }, { $set: { notes: [] } });
}
}
}
(async () => { (async () => {
//await addUpdatedDate(); //await addUpdatedDate();
//await addDebugInfoStatus(); //await addDebugInfoStatus();
await fixNullEvents(); await fixNullNotes();
console.log('====== Done ======'); console.log('====== Done ======');
})(); })();