简体   繁体   English

无法从 Firestore React-Native 获取所有数据

[英]Can't fetch all data from Firestore React-Native

I can't fetch all data from Firestore in my react native app.我无法在我的 React 本机应用程序中从 Firestore 获取所有数据。 I can fetch data when I add a limit(200) parameter but when I take away the limit parameter my app crashes.我可以在添加 limit(200) 参数时获取数据,但是当我删除 limit 参数时,我的应用程序崩溃了。 I need to display all the data and I don't know what I'm doing wrong, here is my code:我需要显示所有数据,但我不知道自己做错了什么,这是我的代码:

  const listingsRef = firebase.firestore().collection(ServerConfiguration.database.collection.LISTINGS);

  if (categoryId === '') {
    console.log('Kommer vi hit???');

    return listingsRef
      .where('isApproved', '==', isApproved)
      .limit(2000)
      .onSnapshot((querySnapshot) => {
        const data = [];

        if (querySnapshot !== undefined) {
          querySnapshot.forEach((doc) => {
            const listing = doc.data();
            if (favorites && favorites[doc.id] === true) {
              listing.saved = true;
            }
            data.push({ ...listing, id: doc.id });
          });

          console.log('KOMMERR datan? : ', data);

          callback(data);
        }
      });
  }

I have tried to use get instead of on Snapshot, and I get the same results.我尝试使用 get 而不是快照,我得到了相同的结果。 I have been stuck for days!我卡了好几天了!

You can replace the limit with getting and getting all the records that satisfy your condition.你可以用获取和获取满足你条件的所有记录来代替限制。

const listingsRef = firebase.firestore().collection(ServerConfiguration.database.collection.LISTINGS);

  if (categoryId === '') {
    console.log('Kommer vi hit???');

    return listingsRef
      .where('isApproved', '==', isApproved)
      .get()
      .onSnapshot((querySnapshot) => {
        const data = [];

        if (querySnapshot !== undefined) {
          querySnapshot.forEach((doc) => {
            const listing = doc.data();
            if (favorites && favorites[doc.id] === true) {
              listing.saved = true;
            }
            data.push({ ...listing, id: doc.id });
          });

          console.log('KOMMERR datan? : ', data);

          callback(data);
        }
      });
  }

But its always a good idea to paginate your results when you have large amount of data但是,当您有大量数据时,对结果进行分页总是一个好主意

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将 Firestore 文档数据加载到 React-Native 中的变量 - Can't load firestore document data to variable in React-Native React-Native 无法从 Firestore 响应中访问二级 - React-Native can't access second level from firestore response React Native 如何从 Firebase Firestore 获取数组数据? - React Native how to fetch Array data from Firebase Firestore? 无法从 React-Native-Firebase(v6) Firestore 获取数据:undefined 不是函数(靠近“...this._firestore.native.collectionGet...”) - Can't get data from React-Native-Firebase(v6) Firestore: undefined is not a function (near '...this._firestore.native.collectionGet...') 如何使用 react-native 在 Firestore 中的嵌套数组上添加数据 - How to add data on nested array in Firestore with react-native 如何从 firestore 获取数据并在 textinput 的下拉列表中列出,以便在 react native 中选择 - How to fetch the data from firestore and list out it in dropdown in textinput for picking in react native 我从 firestore 获取数据,但它没有出现在我的反应本机应用程序屏幕中 - I fetch data from firestore but it's not appearing in my react native app screen undefined 不是 object on react-native expo with firestore - undefined is not an object on react-native expo with firestore Firestore 查询在 react-native 中不起作用 - A firestore query not working in react-native 无法使用 xcode 方案和配置构建 react-native 应用程序 - Can't build react-native app with xcode scheme and configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM