【问题标题】:How to check if current user has filled out a document?如何检查当前用户是否填写了文档?
【发布时间】:2021-01-08 15:27:41
【问题描述】:

我有两个集合,一个是用户,另一个是发票详细信息。在用户登录时,我需要检查当前用户是否填写了发票详细信息集合中的所有字段。因此需要在用户登录后立即显示警报以说明填写详细信息。

两个集合具有相同的 UID

checkJob = () => {

  firebase.firestore().collection('invoice_details').where("accountname", "==", "").get().then((resultSnapShot) => {


          if (resultSnapShot.size == 0) {

              Alert.alert("Details need to be updated")

          } else {

              Alert.alert("Details ok")
          }

      })

  }

【问题讨论】:

    标签: javascript firebase react-native google-cloud-firestore


    【解决方案1】:

    如果您的发票文件是在用户提交一些数据后生成的,那么您可以检查该用户的文件是否存在。

    var docRef = db.collection("invoice_details").doc(userId);
    
    docRef.get().then(function(doc) {
        if (doc.exists) {
            console.log("Document data:", doc.data());
        } else {
            // doc.data() will be undefined in this case
            console.log("No such document!");
        }
    }).catch(function(error) {
        console.log("Error getting document:", error);
    });
    

    【讨论】:

    • @Ding0 是,如果 invoice_details 集合不包含用户密钥文档,则只需对其设置警报
    猜你喜欢
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 2020-03-21
    • 2016-07-13
    • 2021-07-17
    • 2014-04-26
    相关资源
    最近更新 更多