0
0
Firebasecloud~30 mins

Writing data (set, update, push) in Firebase - Mini Project: Build & Apply

Choose your learning style9 modes available
Writing Data in Firebase Realtime Database
📖 Scenario: You are building a simple app to manage a list of tasks. You want to store tasks in Firebase Realtime Database. Each task has a title and a status.
🎯 Goal: Learn how to write data to Firebase Realtime Database using set, update, and push methods.
📋 What You'll Learn
Create an initial task object with exact fields
Create a reference path string for the tasks node
Use set to write a task to a specific path
Use update to change the status of a task
Use push to add a new task with a unique key
💡 Why This Matters
🌍 Real World
Writing and updating data in Firebase Realtime Database is common for apps like to-do lists, chat apps, and real-time dashboards.
💼 Career
Understanding how to write data using set, update, and push is essential for junior cloud developers and mobile app developers working with Firebase.
Progress0 / 4 steps
1
Create initial task data
Create a constant called task with an object containing title set to 'Buy groceries' and status set to 'pending'.
Firebase
Need a hint?

Use const task = { title: 'Buy groceries', status: 'pending' };

2
Create database reference path
Create a constant called tasksRef and set it to the string 'tasks' representing the database path for tasks.
Firebase
Need a hint?

Use const tasksRef = 'tasks';

3
Write task data using set
Write the task object to the database path tasksRef + '/task1' using the set method from Firebase. Use set(ref(database, path), data) syntax.
Firebase
Need a hint?

Use set(ref(database, tasksRef + '/task1'), task); to write data.

4
Update and push tasks
Use update to change the status of task1 to 'completed' at path tasksRef + '/task1'. Then use push to add a new task with title 'Walk the dog' and status 'pending' under tasksRef.
Firebase
Need a hint?

Use update(ref(database, tasksRef + '/task1'), { status: 'completed' }) and push(ref(database, tasksRef), newTask).