0
0
Firebasecloud~30 mins

Updating specific fields in Firebase - Mini Project: Build & Apply

Choose your learning style9 modes available
Updating Specific Fields in Firebase Firestore
📖 Scenario: You are managing a small app's user data stored in Firebase Firestore. You want to update only certain fields of a user's document without changing the entire document.
🎯 Goal: Learn how to update specific fields in a Firestore document using Firebase SDK.
📋 What You'll Learn
Create a Firestore document with initial user data
Add a configuration variable for the user ID
Write code to update specific fields in the Firestore document
Complete the update operation with proper Firestore method
💡 Why This Matters
🌍 Real World
Updating specific fields in Firestore is common when you want to change user profile details without affecting other data.
💼 Career
Knowing how to update fields in Firestore is essential for frontend and backend developers working with Firebase apps.
Progress0 / 4 steps
1
Create initial user data document
Create a Firestore document reference called userDoc pointing to the collection users and document ID user123. Then create an object called initialData with these exact fields: name set to "Alice", age set to 30, and city set to "New York".
Firebase
Need a hint?

Use firestore.collection('users').doc('user123') to get the document reference.

2
Add user ID configuration variable
Create a constant variable called userId and set it to the string "user123".
Firebase
Need a hint?

Define userId before using it in userDoc.

3
Write update data object
Create an object called updateData with these exact fields: age set to 31 and city set to "Boston". This object will hold the fields to update.
Firebase
Need a hint?

Only include the fields you want to change in updateData.

4
Update specific fields in Firestore document
Use the update method on userDoc to update the document with the fields in updateData.
Firebase
Need a hint?

Use userDoc.update(updateData) to change only the specified fields.