Bird
0
0

This Firestore query throws an error:

medium📝 Debug Q7 of 15
GCP - Cloud Firestore and Bigtable
This Firestore query throws an error:
db.collection('events').where('date', '>=', '2023-01-01').orderBy('location')

What is the cause?
AFirestore does not support filtering by date fields.
BInvalid operator '>=' used in where clause.
CorderBy field must be the same as where field for inequality filters.
DMissing composite index for inequality filter on 'date' and orderBy on 'location'.
Step-by-Step Solution
Solution:
  1. Step 1: Check Firestore rules for inequality filters and orderBy

    When using inequality filter on one field and orderBy on another, a composite index is required.
  2. Step 2: Identify cause of error

    Error occurs because composite index for 'date' and 'location' is missing.
  3. Final Answer:

    Missing composite index for inequality filter on 'date' and orderBy on 'location'. -> Option D
  4. Quick Check:

    Inequality + orderBy different field = composite index needed [OK]
Quick Trick: Inequality + orderBy different field needs composite index [OK]
Common Mistakes:
  • Thinking '>=' is invalid operator
  • Assuming orderBy must match where field always
  • Believing Firestore can't filter dates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes