How do you update data in Firestore?

Answer

Firestore provides several update approaches: (1) updateDoc() — updates only specified fields: await updateDoc(docRef, { score: increment(10), lastUpdated: serverTimestamp() }); (2) Dot notation for nested fields — update nested map fields without overwriting the whole map: updateDoc(ref, { "address.city": "New York" }) changes only the city; (3) Special field valuesincrement(n) atomically adds to a number (safe for counters), arrayUnion(value) adds to an array without duplicates, arrayRemove(value) removes from array, deleteField() removes a field, serverTimestamp() sets server-side timestamp; (4) setDoc() with mergesetDoc(ref, data, { merge: true }) creates the document if it doesn't exist, or merges fields if it does — useful for upsert patterns; (5) Transactions — use runTransaction() for conditional updates that read then write atomically.