Query optimization
📖 Scenario: You are building a simple app that stores user profiles in Firebase Firestore. Each profile has a name, age, and city. You want to efficiently get all users from a specific city who are older than a certain age.
🎯 Goal: Build a Firestore query that fetches users from a given city with age greater than a threshold, using query optimization best practices.
📋 What You'll Learn
Create a Firestore collection reference called
usersRef pointing to the 'users' collectionCreate a variable
minAge set to 25Write a Firestore query called
optimizedQuery that fetches users where city equals 'New York' and age is greater than minAgeAdd an index hint comment explaining the need for a composite index on
city and age💡 Why This Matters
🌍 Real World
Filtering user data efficiently in a cloud database is common in apps like social networks or marketplaces.
💼 Career
Knowing how to optimize queries and use indexes in Firestore is essential for backend and cloud developers working with Firebase.
Progress0 / 4 steps