Firestore BasicsBeginner
1Question 1 of 1
javascriptHow does Google Cloud Firestore store data and what is the Collection-Document model?
Explanation & Concept
Cloud Firestore is a flexible, scalable NoSQL cloud database for client and server development. Data is stored in **Documents**, which are grouped into **Collections**.
Documents contain key-value pairs and can contain nested subcollections, forming hierarchical data structures that scale horizontally with high read/write performance.
Code Example
javascript
import { getFirestore, doc, setDoc, getDoc } from "firebase/firestore";
const db = getFirestore();
// Create or update a document in the "cities" collection
await setDoc(doc(db, "cities", "SF"), {
name: "San Francisco",
state: "CA",
country: "USA",
population: 870000
});
// Retrieve document
const docSnap = await getDoc(doc(db, "cities", "SF"));
if (docSnap.exists()) {
console.log("City data:", docSnap.data());
}How It Works & Key Takeaways
Firestore documents are schemaless JSON-like structures that support primitive datatypes, arrays, maps, and GeoPoints.
Mock Test · 1 Questions · Optional
Ready for Authentication?
Take a quick test to evaluate yourself, or move straight to the next module.
Beginner1 questions