简体   繁体   English

如何在 React Native 中从 Firestore 获取所有文档?

[英]How to get All documents from Firestore in React Native?

I had been trying multiple solutions to get all documents from Firebase Firestore.我一直在尝试多种解决方案来从 Firebase Firestore 获取所有文档。 I am working on iOS part, I even added google plist file in iOS project but cannot get back data.我正在处理 iOS 部分,我什至在 iOS 项目中添加了 google plist 文件,但无法取回数据。 Firestore says its been hit multiple times but when it comes to results I see nothing. Firestore 说它被击中了多次,但当谈到结果时,我什么也没看到。

here is code I am using:这是我正在使用的代码:

async function getAnnouncements() {
  const usersCollection = await firestore().collection('Announcements').get();
  console.log(usersCollection);
}

As per the document it should be called as a promise not just as a function.根据文档,它应该被称为 promise 而不仅仅是 function。

import firestore from '@react-native-firebase/firestore';
async function getAnnouncements() {

const usersCollection = await firestore().collection('Users').get()
      .then((querySnapshot) => {
           /*
            A QuerySnapshot allows you to inspect the collection,
            such as how many documents exist within it,
            access to the documents within the collection,
            any changes since the last query and more.
        */

        querySnapshot.forEach((documentSnapshot) => {
          console.log('elements: ', documentSnapshot);
          });
      });
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM