0
0
Firebasecloud~30 mins

Why Realtime Database differs from Firestore in Firebase - See It in Action

Choose your learning style9 modes available
Why Realtime Database differs from Firestore
📖 Scenario: You are learning about Firebase databases. Firebase offers two main database services: Realtime Database and Firestore. Both store data but work differently under the hood.Imagine you want to build a chat app. You need to understand how these two databases handle data storage and updates to choose the right one.
🎯 Goal: Build a simple Firebase configuration that shows the key difference between Realtime Database and Firestore in how they store and update data.
📋 What You'll Learn
Create a Firebase Realtime Database reference with a sample data path
Create a Firestore collection reference with a sample document
Add a configuration variable to switch between Realtime Database and Firestore
Write code to update data in the selected database type
💡 Why This Matters
🌍 Real World
Choosing between Firebase Realtime Database and Firestore is important when building apps that need real-time data syncing, like chat apps or live dashboards.
💼 Career
Understanding these two Firebase databases helps developers design scalable and efficient cloud data storage solutions.
Progress0 / 4 steps
1
Setup Firebase Realtime Database reference
Create a variable called realtimeRef that points to the Firebase Realtime Database path 'chat/messages' using firebase.database().ref().
Firebase
Need a hint?

Use firebase.database().ref('chat/messages') to get the reference.

2
Setup Firestore collection reference
Create a variable called firestoreRef that points to the Firestore collection 'chatMessages' using firebase.firestore().collection().
Firebase
Need a hint?

Use firebase.firestore().collection('chatMessages') to get the collection reference.

3
Add database type configuration
Create a variable called useFirestore and set it to true to select Firestore, or false to select Realtime Database.
Firebase
Need a hint?

Set useFirestore to true or false depending on which database you want to use.

4
Write update logic for selected database
Write code that updates the message { text: 'Hello, world!' } in the selected database. Use firestoreRef.add() if useFirestore is true, otherwise use realtimeRef.push().
Firebase
Need a hint?

Use an if statement to check useFirestore. Call add() on firestoreRef or push() on realtimeRef.