You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 00:38:12