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粉0233267732024-03-21 00:51:29
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()); });