Firebase 9 Firestore GET ALL DOCUMENTS Data From A Collection
Learn how to get all the document data from a collection in Firebase version 9 Cloud Firestore Database using the getDocs() method.
- Get All Documents From A Collection → you’re here
- Get Document By ID
The Firestore Database has a cities collection that has four documents in it like the screenshot below.
Import Firestore Database and de-structure three methods that are:
- getFirestore() → Firestore Database
- doc() → It takes references of the database and collection that we need to get the data from.
- getDocs() → It gets data from collection based references mentioned in the doc() method.
import { getFirestore, doc, getDocs } from https://www.gstatic.com/firebasejs/9.8.4/firebase-firestore.js";
The import statement uses the CDN version of the Firebase SDK in this example.
Initialize Firestore Database
const db = getFirestore();