Option A uses two valid 'where' clauses with supported operators. Option B mixes orderBy and where incorrectly. Option C is incomplete. Option D uses an unsupported operator.
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
✗ Incorrect
Firebase requires a composite index for compound queries on multiple fields to work efficiently.
Which operator is NOT supported in Firebase compound queries?
A==
B<=
C>
Dbetween
✗ Incorrect
'between' is not a supported operator in Firebase queries; use two conditions instead.
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
✗ Incorrect
Firebase provides a direct link to create the required index in the console to fix the error.
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
✗ Incorrect
You can use multiple 'where' clauses on the same field with different operators, like '>=' and '<='.
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.
Practice
(1/5)
1. What does a compound query with multiple .where() filters do in Firebase Firestore?
easy
A. It deletes documents that match the conditions.
B. It finds documents that match any one of the specified conditions.
C. It finds documents that match all the specified conditions.
D. It updates documents that match the conditions.
Solution
Step 1: Understand the purpose of .where() filters
Each .where() filter narrows down the documents by a condition.
Step 2: Combine multiple filters in a compound query
Multiple .where() filters together find documents matching all conditions (AND logic).
Final Answer:
It finds documents that match all the specified conditions. -> Option C
Quick Check:
Compound query = all conditions matched [OK]
Hint: Multiple .where() means all conditions must be true [OK]
Common Mistakes:
Thinking it matches any condition (OR logic)
Confusing query with update or delete
Assuming it returns all documents
2. Which of the following is the correct syntax to create a compound query with two .where() filters in Firebase Firestore?
easy
A. db.collection('users').where(['age', '>=', 18], ['status', '==', 'active'])
B. db.collection('users').where('age', '>=', 18, 'status', '==', 'active')
C. db.collection('users').filter('age', '>=', 18).filter('status', '==', 'active')
D. db.collection('users').where('status', '==', 'active').where('age', '>=', 18)
Solution
Step 1: Review Firestore query chaining syntax
Each .where() is chained separately with three arguments: field, operator, value.
Step 2: Identify correct chaining of two .where() calls
db.collection('users').where('status', '==', 'active').where('age', '>=', 18) correctly chains two .where() calls with proper arguments.
Final Answer:
db.collection('users').where('status', '==', 'active').where('age', '>=', 18) -> Option D
Quick Check:
Separate .where() calls chained = correct syntax [OK]
Hint: Chain separate .where() calls with 3 arguments each [OK]
Firestore error usually provides a link to create the needed composite index.
Final Answer:
Create a composite index for 'category' and 'price' fields as requested by Firestore. -> Option A
Quick Check:
Missing index error = create composite index [OK]
Hint: Create composite index when Firestore asks [OK]
Common Mistakes:
Removing filters instead of creating index
Ignoring Firestore error message
Trying to replace .where() with .orderBy() incorrectly
5. You want to query a Firestore collection 'events' for documents where type is 'conference', attendees is greater than 100, and location is 'NYC'. Which of the following is the best approach to write this compound query and ensure it works efficiently?
hard
A. Chain three .where() filters for each condition and create a composite index for these fields.
B. Use a single .where() with an array of conditions for all fields.
C. Query only by type and filter the rest in client code.
D. Use .orderBy() on all fields instead of .where().
Solution
Step 1: Write the compound query with multiple .where() filters
Use .where('type', '==', 'conference'), .where('location', '==', 'NYC'), and .where('attendees', '>', 100) chained together.
Step 2: Ensure Firestore has a composite index for these fields
Because multiple filters on different fields are used, create a composite index to optimize query performance and avoid errors.
Final Answer:
Chain three .where() filters and create a composite index for these fields. -> Option A
Quick Check:
Multiple filters + composite index = efficient query [OK]
Hint: Chain .where() and create composite index for multiple fields [OK]
Common Mistakes:
Trying to put all conditions in one .where() call
Filtering on client side instead of query
Using .orderBy() instead of .where() for filtering
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.