Мне нужно отобразить данные из 3 коллекций, а затем отсортировать их по дате.Проблема в том, что мне не удается найти правильную структуру данных, чтобы настроить это.Я должен вернуть объект, подобный этому:
data : {
total , // the total ammount of object in collections
data // the datas from all the three collections
}
Вот код, который я пытаюсь настроить:
const fillAray = (callb) => {
let total = 0;
let totalData={}
for(let i=0;i<3;i++){
switch(i){
case 0:
historyPart='1st table'
break;
case 1:
historyPart='2nd table'
break;
case 2:
historyPart='3rd table'
break;
}
const collection_ref = admin.firestore().collection(`*****-${historyPart}`);
const user_transactions_ref = collection_ref.doc(uid).collection('transactions');
user_transactions_ref.orderBy('time', 'desc').get().then(
(snapshot) => {
if (!snapshot.empty) {
snapshot.forEach((doc) => {
++total;
});
}
user_transactions_ref.orderBy('time', 'desc').offset(from).limit(size).get().then(
(snapshot) => {
const out = [];
if (!snapshot.empty) {
snapshot.forEach((doc) => {
out.push(doc.data())
});
}
//merging data
Object.assign(totalData,out)
},
(error) => { callback(error, null); }
);
},
(error) => { callback(error, null); }
);
}
sendDataToFront(totalData,total)
// Here I'm supposed to have totalData and total with all datas
}
Каким-то образом объект не сливается должным образом ...Есть идеи?