Challenge - 5 Problems
Firestore Index Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this Firestore query with missing index?
Consider a Firestore collection
If the required composite index is missing, what will happen?
users with fields age and city. You run this query:db.collection('users').where('age', '>', 25).where('city', '==', 'NYC').get()If the required composite index is missing, what will happen?
Firebase
db.collection('users').where('age', '>', 25).where('city', '==', 'NYC').get()
Attempts:
2 left
💡 Hint
Firestore requires composite indexes for multiple where filters on different fields.
✗ Incorrect
Firestore requires a composite index for queries filtering on multiple fields. If missing, it throws an error with a link to create the index.
🧠 Conceptual
intermediate1:30remaining
Why are composite indexes important in Firestore?
Which of the following best explains why Firestore uses composite indexes?
Attempts:
2 left
💡 Hint
Think about how Firestore handles queries with multiple conditions.
✗ Incorrect
Composite indexes enable Firestore to quickly find documents matching multiple field conditions or sorting orders.
📝 Syntax
advanced2:30remaining
Which Firestore index definition is valid in index configuration file?
Given the Firestore index configuration JSON, which option correctly defines a composite index on
age ascending and city descending for collection users?Firebase
{
"indexes": [
{
"collectionGroup": "users",
"queryScope": "COLLECTION",
"fields": [
{"fieldPath": "age", "order": "ASCENDING"},
{"fieldPath": "city", "order": "DESCENDING"}
]
}
]
}Attempts:
2 left
💡 Hint
Check the exact field names Firestore expects in index config.
✗ Incorrect
Firestore index config uses 'collectionGroup', 'queryScope', and 'order' for field sorting. 'direction' and 'collection' keys are invalid here.
❓ optimization
advanced2:00remaining
How to optimize Firestore queries with multiple filters?
You have a Firestore query filtering on
status and priority fields. Which approach best optimizes query performance?Attempts:
2 left
💡 Hint
Think about how Firestore uses indexes for multiple filters.
✗ Incorrect
Composite indexes allow Firestore to efficiently execute queries with multiple filters without scanning all documents.
🔧 Debug
expert3:00remaining
Why does this Firestore query fail despite having indexes?
You have these indexes:
- Composite index on
- Single-field indexes on
You run this query:
Why does it fail?
- Composite index on
category ascending and date descending- Single-field indexes on
category and dateYou run this query:
db.collection('items').where('category', '==', 'books').orderBy('date', 'asc').get()Why does it fail?
Attempts:
2 left
💡 Hint
Check if index order matches query order.
✗ Incorrect
Firestore requires the index order to match the query's orderBy direction exactly. The composite index has date descending but query orders ascending, so it fails.