What is a Firestore document?

Answer

A Firestore document is a unit of storage containing a set of key-value pairs (fields). Documents are analogous to rows in SQL or objects in JSON. Key characteristics: (1) Identified by an ID — either auto-generated by Firestore or specified by you; full path: /users/user123; (2) Size limit — maximum 1MB per document; (3) Fields — can contain: strings, numbers, booleans, null, timestamps, geopoints, arrays, maps (nested objects), and references to other documents; (4) Subcollections — documents can contain subcollections (nested collections), enabling hierarchical data; (5) Snapshots — when you read a document, you get a DocumentSnapshot containing the data and metadata. Creating: setDoc(doc(db, "users", "user123"), { name: "Alice", age: 30 }). Reading: const snap = await getDoc(doc(db, "users", "user123")); snap.data().