Firebase Firestore: Setting Document Data with Merge Option
📖 Scenario: You are building a simple app that stores user profiles in Firebase Firestore. Sometimes you want to update only part of a user's profile without overwriting the entire document.
🎯 Goal: Learn how to use the set method with the merge: true option to update parts of a Firestore document safely.
📋 What You'll Learn
Create a Firestore document reference for a user with ID 'user123'.
Create an initial user profile object with name and age.
Use
set to save the initial profile to Firestore.Create an update object with a new age and city.
Use
set with { merge: true } to update the user profile without deleting existing fields.💡 Why This Matters
🌍 Real World
Updating user profiles or settings in Firestore without deleting existing data is common in apps.
💼 Career
Understanding how to safely update Firestore documents is essential for backend and full-stack developers working with Firebase.
Progress0 / 4 steps