0
0
Firebasecloud~30 mins

Why Firestore performance needs planning in Firebase - See It in Action

Choose your learning style9 modes available
Why Firestore Performance Needs Planning
📖 Scenario: You are building a simple app that stores user profiles in Firestore. You want to understand how to organize your data and queries so the app runs fast and costs less.
🎯 Goal: Learn how to plan Firestore data structure and queries to improve performance and reduce costs.
📋 What You'll Learn
Create a Firestore collection with user profiles
Add a configuration variable for query limits
Write a query to fetch user profiles with limits
Add an index configuration for efficient queries
💡 Why This Matters
🌍 Real World
Apps that store and retrieve user data need fast and cost-effective database queries.
💼 Career
Understanding Firestore query planning is important for cloud developers and database administrators to optimize app performance.
Progress0 / 4 steps
1
Create a Firestore collection with user profiles
Create a Firestore collection called users with documents that have fields name (string) and age (number). Add exactly three users: {name: 'Alice', age: 30}, {name: 'Bob', age: 25}, and {name: 'Charlie', age: 35}.
Firebase
Need a hint?

Use an array of objects to represent the users collection.

2
Add a configuration variable for query limits
Add a variable called maxResults and set it to 2. This will limit how many user profiles we fetch at once.
Firebase
Need a hint?

Use const maxResults = 2; to set the limit.

3
Write a query to fetch user profiles with limits
Write a Firestore query called query that fetches documents from the users collection, ordered by age, and limited to maxResults.
Firebase
Need a hint?

Use firestore.collection('users').orderBy('age').limit(maxResults) to build the query.

4
Add an index configuration for efficient queries
Add a Firestore index configuration JSON object called indexConfig that defines an index on the users collection with fields age ascending and name ascending.
Firebase
Need a hint?

Define indexConfig as a JSON object with collection, queryScope, and fields array.