Bird
0
0

You wrote this Firestore query:

medium📝 Debug Q6 of 15
GCP - Cloud Firestore and Bigtable
You wrote this Firestore query:
db.collection('users').where('age', '>', 18).where('age', '<', 30).orderBy('age')

But it returns an error about missing index. How do you fix it?
ANo fix needed; Firestore should handle this automatically.
BCreate a composite index on the 'age' field with range filters and orderBy.
CChange orderBy to orderBy('name') to avoid index error.
DRemove one of the where clauses to avoid multiple filters on the same field.
Step-by-Step Solution
Solution:
  1. Step 1: Understand range filters on same field require composite index with orderBy

    Firestore needs a composite index when multiple range filters and orderBy are on the same field.
  2. Step 2: Fix by creating the required composite index

    Create a composite index on 'age' supporting the range filters and orderBy.
  3. Final Answer:

    Create a composite index on the 'age' field with range filters and orderBy. -> Option B
  4. Quick Check:

    Range filters + orderBy same field = composite index needed [OK]
Quick Trick: Range filters + orderBy same field need composite index [OK]
Common Mistakes:
  • Removing filters instead of creating index
  • Changing orderBy field incorrectly
  • Expecting Firestore to auto-fix index errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes