0
0
Firebasecloud~30 mins

Data modeling best practices in Firebase - Mini Project: Build & Apply

Choose your learning style9 modes available
Data Modeling Best Practices with Firebase
📖 Scenario: You are building a simple app to store user profiles and their favorite books using Firebase Firestore. You want to organize your data well so it is easy to read and update.
🎯 Goal: Create a Firebase Firestore data model with collections and documents that follow best practices for structuring user profiles and their favorite books.
📋 What You'll Learn
Create a users collection with user documents
Each user document must have name and email fields
Add a favoriteBooks subcollection inside each user document
Each book document in favoriteBooks must have title and author fields
💡 Why This Matters
🌍 Real World
This data model is useful for apps that store user profiles and their related data, like favorite items or preferences, in a clear and scalable way.
💼 Career
Understanding Firebase data modeling is essential for cloud developers and backend engineers working with NoSQL databases and real-time apps.
Progress0 / 4 steps
1
Create the users collection with user documents
Create a Firebase Firestore data structure with a users collection containing two user documents. Each user document should have the exact fields: name and email. Use the user IDs user1 and user2 with these values: name: "Alice", email: "alice@example.com" for user1 and name: "Bob", email: "bob@example.com" for user2.
Firebase
Need a hint?

Think of users as a collection holding documents named user1 and user2. Each document is an object with name and email.

2
Add a favoriteBooks subcollection for each user
Add a favoriteBooks subcollection inside each user document in the users collection. For now, create empty favoriteBooks objects for both user1 and user2.
Firebase
Need a hint?

Think of favoriteBooks as a small collection inside each user document. Start with empty objects to hold books later.

3
Add book documents inside favoriteBooks subcollections
Inside the favoriteBooks subcollection for user1, add two book documents with IDs book1 and book2. Each book document must have title and author fields. Use these exact values: book1 with title: "1984" and author: "George Orwell", and book2 with title: "Brave New World" and author: "Aldous Huxley". Leave user2's favoriteBooks empty for now.
Firebase
Need a hint?

Inside user1.favoriteBooks, add two objects named book1 and book2 with the given fields.

4
Complete the data model with proper nesting
Ensure the entire Firebase Firestore data model is a single JavaScript object named users with user documents containing name, email, and a favoriteBooks subcollection. Confirm that user1 has two book documents and user2 has an empty favoriteBooks subcollection.
Firebase
Need a hint?

Review the entire object to confirm all parts are present and correctly nested.