Challenge - 5 Problems
Ordering Results Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate2:00remaining
Ordering Firestore query results by a single field
You have a Firestore collection named products with documents containing a
Which query will return the products correctly ordered by price ascending?
price field. You want to retrieve all products ordered by price from lowest to highest.Which query will return the products correctly ordered by price ascending?
Attempts:
2 left
💡 Hint
Remember that Firestore orderBy accepts 'asc' or 'desc' as direction strings.
✗ Incorrect
Option A uses the correct method to order by 'price' ascending using 'asc'. Option A orders descending, so order is reversed. Option A omits the direction, which defaults to ascending but is less explicit. Option A uses 'ascending' which is invalid and causes an error.
❓ Configuration
intermediate2:00remaining
Ordering Realtime Database results by child key
You want to retrieve all users from Firebase Realtime Database ordered by their
Which query correctly orders the users by age ascending?
age field.Which query correctly orders the users by age ascending?
Attempts:
2 left
💡 Hint
Use orderByChild to order by a specific child key.
✗ Incorrect
Option D correctly orders by the child key 'age' and retrieves the full snapshot once. Option D tries to order by key but passes 'age' which is invalid. Option D orders by value but 'age' is a child, not the value itself. Option D uses 'child_added' event which triggers multiple times, not a single snapshot.
❓ Architecture
advanced2:00remaining
Designing Firestore queries with multiple orderBy clauses
You have a Firestore collection
Which query correctly implements this ordering?
tasks with fields priority (number) and dueDate (timestamp). You want to query tasks ordered first by priority ascending, then by dueDate descending.Which query correctly implements this ordering?
Attempts:
2 left
💡 Hint
The order of orderBy calls matters and direction must be specified explicitly when descending.
✗ Incorrect
Option A orders by priority ascending first, then dueDate descending as required. Option A reverses the order of fields. Option A orders both ascending by default, not matching the requirement. Option A reverses directions.
❓ security
advanced2:00remaining
Firestore security rules impact on ordered queries
You have a Firestore collection
Which security rule snippet correctly allows read access only if the query orders by
messages with a field timestamp. You want to allow users to read messages ordered by timestamp.Which security rule snippet correctly allows read access only if the query orders by
timestamp ascending?Attempts:
2 left
💡 Hint
Firestore security rules use arrays for orderBy and orderByDirection properties.
✗ Incorrect
Option B correctly checks the first element of orderBy and orderByDirection arrays. Option B compares arrays directly which is invalid. Options B and C use incorrect property names or types.
✅ Best Practice
expert2:00remaining
Optimizing Firestore queries with ordering and indexing
You have a Firestore collection
Which approach is best to ensure the query is efficient and does not require manual index creation?
orders with fields status (string) and createdAt (timestamp). You want to query orders where status is 'pending' ordered by createdAt descending.Which approach is best to ensure the query is efficient and does not require manual index creation?
Attempts:
2 left
💡 Hint
Firestore requires composite indexes for queries with multiple filters and orderBy on different fields.
✗ Incorrect
Option C creates the required composite index explicitly, ensuring efficient queries. Option C orders by status unnecessarily and lacks index. Option C relies on auto-index creation which may cause runtime errors until index is created. Option C filters client-side which is inefficient and costly.