Ghulam Rasool
Ghulam Rasool

Reputation: 78

How to get All documents from Firestore in React Native?

I had been trying multiple solutions to get all documents from Firebase Firestore. I am working on iOS part, I even added google plist file in iOS project but cannot get back data. Firestore says its been hit multiple times but when it comes to results I see nothing.

here is code I am using:

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

Upvotes: 0

Views: 689

Answers (1)

Sathi Aiswarya
Sathi Aiswarya

Reputation: 2950

As per the document it should be called as a promise not just as a 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);
          });
      });
}

Upvotes: 1

Related Questions