0
0
Firebasecloud~30 mins

Nested objects and arrays in Firebase - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested objects and arrays
📖 Scenario: You are setting up a Firebase Firestore database for a small online bookstore. You want to organize the data so that each book document contains nested information about the author and an array of reviews.
🎯 Goal: Create a Firestore document structure with nested objects for author details and an array of review objects inside a book document.
📋 What You'll Learn
Create a Firestore document called book with nested author information
Include an array called reviews inside the book document
Each review in the reviews array should be an object with reviewer and comment fields
Use valid Firestore data types and structure
💡 Why This Matters
🌍 Real World
Organizing complex data like books with authors and reviews in Firestore for a real online bookstore.
💼 Career
Understanding nested data structures and arrays in Firestore is essential for backend cloud developers working with NoSQL databases.
Progress0 / 4 steps
1
Create the initial book document with title and author nested object
Create a Firestore document called book with a title field set to "The Great Gatsby" and a nested author object containing name set to "F. Scott Fitzgerald" and birthYear set to 1896.
Firebase
Need a hint?

Use a dictionary with a nested dictionary for the author.

2
Add an empty reviews array to the book document
Add an empty array called reviews to the existing book document.
Firebase
Need a hint?

Add a key "reviews" with an empty list as its value.

3
Add two review objects to the reviews array
Add two review objects to the reviews array inside the book document. The first review should have reviewer set to "Alice" and comment set to "Loved the vivid characters.". The second review should have reviewer set to "Bob" and comment set to "A timeless classic.".
Firebase
Need a hint?

Each review is a dictionary inside the list assigned to reviews.

4
Complete the Firestore document structure for deployment
Assign the book dictionary to a Firestore document reference called doc_ref using the method set() to save the data. Assume db is your Firestore client and the collection is called books. Write the line of code that sets the document with ID gatsby.
Firebase
Need a hint?

Use db.collection("books").document("gatsby") to get the document reference, then call set(book).