....................
let insertDocument = [];
for (var obj of json.data) {
let cityType;
if(obj.SettlementTypeDescription === 'місто') {
cityType = 1;
cityMark = 'м.';
cityMarkRu = 'г.';
}else if(obj.SettlementTypeDescription === 'селище міського типу') {
cityType = 2;
cityMark = 'смт.';
cityMarkRu = 'пгт.';
}else if(obj.SettlementTypeDescription === 'село') {
cityType = 3;
cityMark = 'с.';
cityMarkRu = 'с.';
}else if(obj.SettlementTypeDescription === 'селище') {
cityType = 3;
cityMark = 'сел.';
cityMarkRu = 'пос.';
}
let newCityObj = {
_id: obj.Ref,
redionId: obj.Region,
areaId: obj.Area,
lat: obj.Latitude,
lng: obj.Longitude,
index: obj.Index1,
fullTitle: {
ua: `${cityMark} ${obj.Description}, ${obj.RegionsDescription}, ${obj.AreaDescription}`,
ru: `${cityMarkRu} ${obj.DescriptionRu}, ${obj.RegionsDescriptionRu}, ${obj.AreaDescriptionRu}`
},
title: {
ua: obj.Description,
ru: obj.DescriptionRu
},
regionTitle: {
ua: obj.RegionsDescription,
ru: obj.RegionsDescriptionRu
},
areaTitle: {
ua: obj.AreaDescription,
ru: obj.AreaDescriptionRu
},
typeTitle: {
ua: obj.SettlementTypeDescription,
ru: obj.SettlementTypeDescriptionRu
},
type:cityType
}
insertDocument.push({
"updateOne": {
"filter": { "_id": obj.Ref },
"update": { $set : newCityObj },
"upsert": true
}
});
}
// Добавляем/обновляем город в БД
saveCity(insertDocument)
...........
async function saveCity(obj) {
const cities = await loadCities();
await cities.bulkWrite(obj)
}
Блокировать поля формы (disabled) пока не придет ответ от сервера