Access data from Firebase collections
P粉201448898
P粉201448898 2024-03-20 11:42:54
0
1
327

I'm trying to read information from a Firebase collection in React, but I can only read one using this code. Can anyone help me?

This is my code, returns only one element

async function(){
  const docRef = doc(db, "transactions/yaounde/income/GWL5xaGgrSvmaYNXhSLx");
  const docSnap = await getDoc(docRef);
  if (docSnap.exists()) {
    console.log("Document data:", docSnap.data());
  } else {
    console.log(docSnap.data())
    console.log("No such document!");
  }
};

I've tried reducing the number of quoted midsections but it returns undefined

P粉201448898
P粉201448898

reply all(1)
P粉023326773

Excerpted from the Firebase documentation on Reading multiple documents from a collection一>:

import { collection, getDocs } from "firebase/firestore";

const querySnapshot = await getDocs(collection(db, "cities"));
querySnapshot.forEach((doc) => {
  // doc.data() is never undefined for query doc snapshots
  console.log(doc.id, " => ", doc.data());
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template