【问题标题】:cant get document in firestore(React Native)无法在 Firestore 中获取文档(React Native)
【发布时间】:2020-10-10 19:08:51
【问题描述】:

我正在尝试从 firestore 获取文档值,但我的查询出现错误。

这是 Firebase 中的路径:

/users/currentuser.uid/confirmed-appointments/10/10

这是我的使用效果:

  useEffect(() => {
    const currentMonth = new Date().getMonth() + 1; //Later be used here
    firebase
      .firestore()
      .collection("users")
      .doc(uid)
      .collection("confirmed-appointments")
      .doc("10") //10 = october , 11 = november , 12 = december and etc....
      .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!");
        }
      })

  }, [])

我想浏览 10 月 10 日内的所有文档

【问题讨论】:

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


    【解决方案1】:

    只需使用完整路径对子集合执行普通查询:

    firebase
      .firestore()
      .collection("users")
      .doc(uid)
      .collection("confirmed-appointments")
      .doc("10")
      .collection("10")
      .get().then(querySnapshot => {
        for (const doc of querySnapshot.docs) {
          console.log("Document data:", doc.data());
        }
      })
    

    【讨论】:

      猜你喜欢
      • 2019-06-07
      • 1970-01-01
      • 2021-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多