【问题标题】:Firebase problem documentSnapChot.forEachFirebase 问题文档SnapChot.forEach
【发布时间】:2021-03-10 15:14:48
【问题描述】:

我有一个名为“TeamArray”的数组,我通过 firebase 上的数据库向其中发送数据

firestore()
            .collection("Teams")
            .where("City", "==", data.structured_formatting.main_text)
            .get()
            .then((querySnapshot) => {
              if (querySnapshot.empty) {
                console.log("no documents found");
              } else {
                querySnapshot.forEach(async (doc) => {
                  let Teams = doc._data;
                  updateTeamArray([Teams]);
                  console.log(TeamArray);
                });
              }

当我触发该功能时,我要求 firestore 只给我与过滤器匹配的数据,并且其中有几个。我只想接收一个包含所有数据的数组,而“doc._data”却一一给我数据。

【问题讨论】:

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


    【解决方案1】:

    你试试这段代码。希望您的查询将得到解决。我也像这样从 Firebase 搜索数据。

             firestore()
            .collection("Teams")
            .where("City", "==", data.structured_formatting.main_text)
            .get()
            .then((querySnapshot) => {
              if (querySnapshot.empty) {
                console.log("no documents found");
              } else {
                querySnapshot.forEach(async (doc) => {
                  let Teams = doc._data;
                  TeamArray.push(doc._data())
                  console.log(TeamArray);
                });
              }
    

    【讨论】:

      猜你喜欢
      • 2020-01-11
      • 2020-08-24
      • 1970-01-01
      • 2022-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      相关资源
      最近更新 更多