首页 > 解决方案 > 无法通过在 REACT 中使用 Google 身份验证使用登录 ID 从 Firestore 读取数据。我的数据以当前使用的 ID 保存在 Firestore 中

问题描述

[无法通过使用谷歌身份验证的登录 ID 来读取来自 Firestore 的数据。我检查了我的数据是否以当前使用的 ID 保存在 Firestore 中。]

 db.collection('demo').where('uid', '=', firebase.auth().currentUser.uid)
     .get()
     .then(snapshot => {
      const demo = []
      snapshot.forEach(doc =>{
        const data = doc.data()
        demo.push(data)
      })
      this.setState({demo:demo})
})
    .catch(error => console.log(error))
    
    })

<[1]: https://i.stack.imgur.com/ktOCW.png>

标签: reactjsgoogle-cloud-firestore

解决方案


您所做的查询不正确,您应该使用==而不是=,所以它应该如下所示:

db.collection('demo').where('uid', '==', firebase.auth().currentUser.uid)

推荐阅读