0
0
GCPcloud~30 mins

Firestore queries and indexes in GCP - Mini Project: Build & Apply

Choose your learning style9 modes available
Firestore Queries and Indexes
📖 Scenario: You are building a simple app to manage a library's book collection using Google Firestore. You want to organize the data and run queries efficiently.
🎯 Goal: Create a Firestore collection with book data, add a configuration for filtering, write a query to find books by a specific author, and finally configure a composite index to support the query.
📋 What You'll Learn
Create a Firestore collection named books with specific book documents
Add a variable to filter books by the author "Jane Austen"
Write a Firestore query to get books where author equals the filter variable
Add a composite index configuration for author and publishedYear
💡 Why This Matters
🌍 Real World
Firestore is used to store and query data in many apps. Knowing how to structure data and indexes helps apps run fast and scale well.
💼 Career
Cloud engineers and developers often configure Firestore queries and indexes to optimize app performance and cost.
Progress0 / 4 steps
1
Create the Firestore collection with book documents
Create a Firestore collection named books with these exact documents: {"title": "Pride and Prejudice", "author": "Jane Austen", "publishedYear": 1813}, {"title": "Emma", "author": "Jane Austen", "publishedYear": 1815}, and {"title": "1984", "author": "George Orwell", "publishedYear": 1949}.
GCP
Need a hint?

Use a list named books with dictionaries for each book.

2
Add a filter variable for author
Create a variable called author_filter and set it to the string "Jane Austen" to filter books by this author.
GCP
Need a hint?

Assign the exact string "Jane Austen" to author_filter.

3
Write a Firestore query to get books by the author filter
Write a Firestore query named query that filters the books collection where the author field equals the variable author_filter.
GCP
Need a hint?

Use a list comprehension named query to filter books by author_filter.

4
Add a composite index configuration for author and publishedYear
Add a Firestore composite index configuration named composite_index as a dictionary with collectionId set to "books", and fields as a list of dictionaries for author ascending and publishedYear descending.
GCP
Need a hint?

Define composite_index as a dictionary with the required keys and list of fields.