How do you read data from Firestore?

Answer

Reading Firestore data uses two approaches: (1) One-time fetchgetDoc() for a single document: const snap = await getDoc(doc(db, "users", "alice")); if (snap.exists()) { console.log(snap.data()) }. getDocs() for a collection: const q = query(collection(db, "posts"), orderBy("createdAt")); const snaps = await getDocs(q); snaps.forEach(doc => console.log(doc.id, doc.data())); (2) Real-time listeneronSnapshot() subscribes to changes: const unsub = onSnapshot(doc(db, "users", "alice"), snap => { console.log(snap.data()) }). The callback fires immediately with current data and again whenever the document changes. unsub() stops listening. Real-time listeners are the core of Firestore's real-time capabilities — use them when the UI must reflect live data. Prefer one-time fetches for data that only needs to be loaded once (profile pages, settings).