Challenge - 5 Problems
Firestore Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate2:00remaining
Firestore Query Result Count
You have a Firestore collection named users with documents containing fields
What will be the number of documents returned if the collection has:
- 5 users aged 30 in Seattle
- 3 users aged 20 in Seattle
- 4 users aged 40 in New York
- 2 users aged 50 in Seattle?
age (number) and city (string). You run this query:db.collection('users').where('age', '>', 25).where('city', '==', 'Seattle').get()What will be the number of documents returned if the collection has:
- 5 users aged 30 in Seattle
- 3 users aged 20 in Seattle
- 4 users aged 40 in New York
- 2 users aged 50 in Seattle?
Attempts:
2 left
💡 Hint
Remember the query filters on age > 25 and city == 'Seattle'.
✗ Incorrect
The query filters users older than 25 and located in Seattle. Only 5 users aged 30 in Seattle and 2 users aged 50 in Seattle match both filters, so total is 7. The options show 7 as B, so the correct answer is B.
❓ Architecture
intermediate2:00remaining
Firestore Composite Index Requirement
You want to run this Firestore query:
Which statement about indexes is true?
db.collection('orders').where('status', '==', 'shipped').orderBy('date', 'desc').limit(10)Which statement about indexes is true?
Attempts:
2 left
💡 Hint
Think about how Firestore handles queries with filters and orderBy on different fields.
✗ Incorrect
Firestore requires a composite index when a query filters on one field and orders by another. Here, filtering on 'status' and ordering by 'date' needs a composite index on both fields.
❓ security
advanced2:00remaining
Firestore Query and Security Rules
Given this Firestore security rule:
What happens if a user runs a query filtering documents by
allow read: if request.auth.uid == resource.data.ownerId;What happens if a user runs a query filtering documents by
ownerId equal to their UID?Attempts:
2 left
💡 Hint
Security rules filter access after the query runs, but queries must match rules to succeed.
✗ Incorrect
Firestore evaluates security rules on each document returned by the query. If the query filters by ownerId equal to the user's UID, only authorized documents are returned.
✅ Best Practice
advanced2:00remaining
Optimizing Firestore Query Performance
You have a Firestore collection with millions of documents. You want to query documents where
category is 'books' and price is less than 20, ordered by price. Which approach is best for performance?Attempts:
2 left
💡 Hint
Indexes help Firestore quickly find matching documents without scanning all data.
✗ Incorrect
A composite index on 'category' and 'price' supports filtering and ordering efficiently. Separate queries or client-side filtering cause performance issues.
🧠 Conceptual
expert2:00remaining
Firestore Query Limitations and Indexes
Which Firestore query is NOT possible without creating a custom composite index?
Attempts:
2 left
💡 Hint
Consider Firestore's support for range filters on multiple fields.
✗ Incorrect
Firestore does not support range filters on multiple fields in a single query without a composite index. Option C uses two range filters (> and <) on different fields, which requires a composite index.