0
0
Firebasecloud~30 mins

Document-collection data model in Firebase - Mini Project: Build & Apply

Choose your learning style9 modes available
Building a Simple Firestore Document-Collection Structure
📖 Scenario: You are creating a small app to store information about books in a library. Each book has a title, author, and year published. You will use Firestore's document-collection model to organize this data.
🎯 Goal: Build a Firestore structure with a collection called books. Each document in books will represent one book with fields for title, author, and year.
📋 What You'll Learn
Create a collection named books.
Add three book documents with exact fields and values.
Use a variable libraryRef to reference the books collection.
Write code to add a new book document to the books collection.
💡 Why This Matters
🌍 Real World
Firestore's document-collection model is used in many apps to store structured data like user profiles, product catalogs, or blog posts.
💼 Career
Understanding how to organize data in Firestore is essential for frontend and backend developers working with Firebase to build scalable, real-time applications.
Progress0 / 4 steps
1
Create the books collection with initial book documents
Create a Firestore collection reference called books and add three documents with these exact fields and values:
{ title: 'The Great Gatsby', author: 'F. Scott Fitzgerald', year: 1925 },
{ title: '1984', author: 'George Orwell', year: 1949 },
{ title: 'To Kill a Mockingbird', author: 'Harper Lee', year: 1960 }.
Firebase
Need a hint?

Use collection(db, 'books') to create the collection reference. Use addDoc to add each book document.

2
Create a variable libraryRef to reference the books collection
Create a new constant called libraryRef and assign it the value of the books collection reference.
Firebase
Need a hint?

Assign libraryRef the value of books.

3
Add a new book document using libraryRef
Use await addDoc with libraryRef to add a new book document with these exact fields:
{ title: 'Brave New World', author: 'Aldous Huxley', year: 1932 }.
Firebase
Need a hint?

Use await addDoc(libraryRef, { ... }) to add the new book.

4
Complete the Firestore setup with proper async function wrapper
Wrap all Firestore calls inside an async function called setupLibrary and call it at the end of the code.
Firebase
Need a hint?

Define an async function setupLibrary that contains all Firestore calls, then call it.