Migration for adding status to debugInfo

This commit is contained in:
Selim Mustafaev 2021-01-31 16:18:47 +03:00
parent 0194f3472b
commit 0d1bce9b67

View File

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