【问题标题】:Firestore: Checking snapshot.exists always returns false even though there are documents in the collectionFirestore:即使集合中有文档,检查 snapshot.exists 总是返回 false
【发布时间】:2020-06-22 17:55:42
【问题描述】:

这是我的 Firestore 设置。如您所见,此集合中有文档。

这是我获取集合中文档快照的代码。它总是返回假。有人可以帮我弄清楚如何解决它吗?

firebase.firestore().collection("chatMessages").doc("chatMessages").collection(chatId).get()
  .then((snapshot) => {
    if (snapshot.exists) { // <- always returning false
      console.log("snapshot exists");
    }
  })
}

【问题讨论】:

    标签: firebase google-cloud-firestore


    【解决方案1】:

    对于查询,没有.exists 属性——这是DocumentSnapshot 的属性,而不是QuerySnapshot。我想你想要empty

    if (!snapshot.empty) {
      console.log('query returned results');
    }
    

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-02
        • 1970-01-01
        • 1970-01-01
        • 2019-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-08
        相关资源
        最近更新 更多