0
0
Firebasecloud~5 mins

Compound queries (multiple where) in Firebase - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a compound query in Firebase?
A compound query in Firebase is a query that uses more than one 'where' condition to filter documents based on multiple criteria.
Click to reveal answer
beginner
Can you use multiple 'where' clauses on different fields in a single Firebase query?
Yes, Firebase allows multiple 'where' clauses on different fields to create compound queries, as long as the fields are indexed properly.
Click to reveal answer
intermediate
Why do you need indexes for compound queries in Firebase?
Indexes help Firebase quickly find documents that match multiple conditions. Without indexes, compound queries may fail or be slow.
Click to reveal answer
beginner
Example: How to query documents where 'status' is 'active' and 'age' is greater than 25?
Use: collection.where('status', '==', 'active').where('age', '>', 25)
Click to reveal answer
intermediate
What happens if you try a compound query without the required index in Firebase?
Firebase will return an error with a link to create the needed index automatically in the Firebase console.
Click to reveal answer
Which of these is a valid compound query in Firebase?
Acollection.where('type', '==', 'book').where('price', '<', 20)
Bcollection.where('type', '==', 'book').orderBy('type').where('price', '<', 20)
Ccollection.where('type', '==', 'book').where('price')
Dcollection.where('type', '==', 'book').where('price', 'between', 10, 20)
What must you do before running a compound query on multiple fields in Firebase?
AEnable multi-field queries in settings
BCreate a composite index for those fields
CUse only one 'where' clause
DNothing special, it works by default
Which operator is NOT supported in Firebase compound queries?
A==
B<=
C>
Dbetween
If Firebase returns an error about missing index, what should you do?
ACreate the index using the provided link
BIgnore it and retry
CRemove one 'where' clause
DSwitch to a different database
Can you use multiple 'where' clauses on the same field in Firebase?
AYes, but only with '==' operator
BNo, only one 'where' per field
CYes, with different operators
DOnly if the field is indexed twice
Explain how to build a compound query in Firebase and what you need to consider about indexes.
Think about filtering by more than one condition and how Firebase handles that.
You got /4 concepts.
    Describe what happens if you run a compound query without the necessary index in Firebase.
    Consider Firebase's way of guiding you to fix missing indexes.
    You got /4 concepts.