0
0
Firebasecloud~20 mins

Index management in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firestore Index Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this Firestore query with missing index?
Consider a Firestore collection 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()
AThe query returns no results but does not throw an error.
BThe query returns users filtered only by age, ignoring city.
CThe query throws an error indicating a missing index and provides a link to create it.
DThe query returns all users older than 25 in NYC without error.
Attempts:
2 left
💡 Hint
Firestore requires composite indexes for multiple where filters on different fields.
🧠 Conceptual
intermediate
1:30remaining
Why are composite indexes important in Firestore?
Which of the following best explains why Firestore uses composite indexes?
ATo allow queries filtering or sorting on multiple fields efficiently.
BTo store data redundantly for backup purposes.
CTo encrypt data fields for security.
DTo automatically generate reports from data.
Attempts:
2 left
💡 Hint
Think about how Firestore handles queries with multiple conditions.
📝 Syntax
advanced
2: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"}
      ]
    }
  ]
}
A{ "collectionGroup": "users", "queryScope": "COLLECTION", "fields": [ {"fieldPath": "age", "direction": "ASC"}, {"fieldPath": "city", "direction": "DESC"} ] }
B{ "collectionGroup": "users", "queryScope": "COLLECTION", "fields": [ {"fieldPath": "age", "order": "ASCENDING"}, {"fieldPath": "city", "order": "DESCENDING"} ] }
C{ "collection": "users", "fields": [ {"fieldPath": "age", "order": "ASCENDING"}, {"fieldPath": "city", "order": "DESCENDING"} ] }
D{ "collectionGroup": "users", "queryScope": "COLLECTION", "fields": [ {"fieldPath": "age", "order": "ASC"}, {"fieldPath": "city", "order": "DESC"} ] }
Attempts:
2 left
💡 Hint
Check the exact field names Firestore expects in index config.
optimization
advanced
2: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?
AUse only one filter at a time to avoid needing indexes.
BCreate separate single-field indexes on <code>status</code> and <code>priority</code>.
CAvoid indexes and filter results client-side after fetching all documents.
DCreate a composite index on <code>status</code> and <code>priority</code> fields.
Attempts:
2 left
💡 Hint
Think about how Firestore uses indexes for multiple filters.
🔧 Debug
expert
3:00remaining
Why does this Firestore query fail despite having indexes?
You have these indexes:
- Composite index on category ascending and date descending
- Single-field indexes on category and date

You run this query:

db.collection('items').where('category', '==', 'books').orderBy('date', 'asc').get()

Why does it fail?
AThe composite index orders <code>date</code> descending but query orders ascending, causing mismatch.
BThe single-field index on <code>date</code> is missing.
CFirestore does not support ordering by <code>date</code> after filtering by <code>category</code>.
DThe query is missing a limit clause.
Attempts:
2 left
💡 Hint
Check if index order matches query order.