Firebase中Promise关联clients与typeclients集合的问题及代码修复
修复后的关联查询代码
async function getListClient() { try { const querySnapshot = await getDocs(collection(db, "clients")); const clientPromises = querySnapshot.docs.map(async (clientRef) => { const typeClientRef = doc(db, "typeclients", clientRef.data().idTypeClient); const typeClientSnap = await getDoc(typeClientRef); const typeClientLabel = typeClientSnap.exists ? typeClientSnap.data().label : ""; return { id: clientRef.id, name: clientRef.data().name, website: clientRef.data().website, typeClientLabel: typeClientLabel }; }); const tabClient = await Promise.all(clientPromises); return tabClient; } catch (e) { console.error("Error fetching documents: ", e); throw e; } }
内容的提问来源于stack exchange,提问作者Jean François Manatane
相关产品推荐
相关产品推荐

