Challenge - 5 Problems
Firestore Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate2:00remaining
Understanding Firestore Query Index Requirements
You have a Firestore collection with documents containing fields: age (number), city (string), and status (string). You run this query:
What will happen when you run this query without any additional setup?
collection.where('age', '>', 25).where('city', '==', 'Seattle').orderBy('status')What will happen when you run this query without any additional setup?
Attempts:
2 left
💡 Hint
Firestore requires composite indexes for queries with multiple where filters and orderBy on different fields.
✗ Incorrect
Firestore needs a composite index when you combine multiple where filters with an orderBy on a different field. Without it, the query fails and prompts you to create the index.
❓ Architecture
intermediate2:00remaining
Optimizing Firestore Queries for Large Collections
You have a Firestore collection with millions of documents. You want to efficiently fetch documents where status is 'active' and order them by createdAt descending. Which approach is best to optimize query performance?
Attempts:
2 left
💡 Hint
Filtering and ordering in the query with proper indexes is more efficient than client-side filtering.
✗ Incorrect
Using a composite index on status and createdAt allows Firestore to efficiently filter and order documents server-side, reducing data transfer and latency.
❓ security
advanced2:00remaining
Securing Firestore Queries with Rules and Indexes
You want to allow users to query their own orders by userId and filter by orderStatus. You create a composite index on userId and orderStatus. Which Firestore security rule best ensures users can only query their own orders?
Attempts:
2 left
💡 Hint
Security rules should restrict access based on user identity matching document fields.
✗ Incorrect
Rule A restricts reads to documents where the userId matches the authenticated user's ID, ensuring users only access their own orders.
✅ Best Practice
advanced2:00remaining
Reducing Firestore Query Costs with Pagination
You have a Firestore query that returns thousands of documents. To reduce cost and improve performance, what is the best practice to paginate results?
Attempts:
2 left
💡 Hint
Firestore charges for documents read, so fetching only needed documents is best.
✗ Incorrect
Using limit() with cursors like startAfter() fetches only the needed documents per page, reducing reads and cost. Using offset() still reads skipped documents, increasing cost.
🧠 Conceptual
expert2:00remaining
Analyzing Firestore Query Execution Behavior
Consider a Firestore collection with documents having fields: category, price, and rating. You run this query:
Which statement best describes how Firestore executes this query?
collection.where('category', '==', 'books').orderBy('price').orderBy('rating')Which statement best describes how Firestore executes this query?
Attempts:
2 left
💡 Hint
Multiple orderBy clauses require a composite index covering all fields in order.
✗ Incorrect
Firestore requires a composite index that includes all where and orderBy fields in the correct order to execute such queries efficiently.