我需要显示 3 个集合中的数据,然后按日期对它们进行排序。问题是我无法找到正确的数据结构来设置它。
我必须返回一个像这样的对象:
data : {
total, // the total number of objects in collections
data // the data from all the three collections
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试设置的代码:
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;
});
} …Run Code Online (Sandbox Code Playgroud)