当我尝试forEach()时,Firebase Cloud Function给出了错误“函数返回了未定义,预期的承诺或值”

时间:2020-05-05 06:34:39

标签: javascript firebase google-cloud-firestore google-cloud-functions

使用匹配的电子邮件逐步吸引eact客户

db.collection("organization")
      .doc(glob_orgID)
      .get()
      .then((snapshot) => {
        const n_email = snapshot.data().owneremail;
        console.log("new email from param2 =" + n_email);
        glob_email = n_email;

        db.collection("customers")
          .where("email", "==", glob_email)
          .onSnapshot((querySnapshot) => {
            var cust = [];
            querySnapshot.forEach((doc) => {
              // cust.push(doc.data().customerId);
              console.log("foreach data = ", doc.ref.id);
              return null;
            });
            console.log("Current email is : ", glob_email);
            console.log("Current cust with join : ", cust.join(","));
          });
        console.log("doc exists + " + snapshot.exists);
        return "doc exists:" + snapshot.exists;
      })
      .catch((err) => {
        console.error("Error getting customers doc", err);
        process.exit();
      });
    console.log("WTF happended???");  
  });

1 个答案:

答案 0 :(得分:0)

您需要在地图中的每个项目上使用doc.data()方法。请尝试:

querySnapshot.map((doc) => {
              console.log(doc.data());
              return null;
            });