Challenge - 5 Problems
Firestore Where Clause Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Filtering documents with a single where clause
Given a Firestore collection
Assuming the collection has these documents:
- {name: 'Alice', age: 30, city: 'NY'}
- {name: 'Bob', age: 22, city: 'LA'}
- {name: 'Carol', age: 27, city: 'NY'}
- {name: 'Dave', age: 24, city: 'SF'}
users with documents containing fields age and city, what will be the output of this query?db.collection('users').where('age', '>', 25).get()Assuming the collection has these documents:
- {name: 'Alice', age: 30, city: 'NY'}
- {name: 'Bob', age: 22, city: 'LA'}
- {name: 'Carol', age: 27, city: 'NY'}
- {name: 'Dave', age: 24, city: 'SF'}
Firebase
db.collection('users').where('age', '>', 25).get()
Attempts:
2 left
💡 Hint
Think about which users have age greater than 25.
✗ Incorrect
The query filters users where age is greater than 25. Alice (30) and Carol (27) meet this condition.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in a Firestore where clause
Which option contains a syntax error in the Firestore query using
where clause?Firebase
db.collection('products').where('price' '>=', 100).get()
Attempts:
2 left
💡 Hint
Check the commas and operator spelling in the where clause.
✗ Incorrect
Option D is missing a comma between 'price' and '>=' causing a syntax error.
❓ optimization
advanced2:30remaining
Optimizing multiple where clauses in Firestore
You want to query a collection
orders to find documents where status is 'shipped' and total is greater than 50. Which query is optimized and valid in Firestore?Attempts:
2 left
💡 Hint
Firestore supports chaining multiple where clauses separately.
✗ Incorrect
Option B chains two where clauses correctly. Other options have invalid syntax or unsupported operators.
🧠 Conceptual
advanced2:00remaining
Understanding Firestore where clause limitations
Which statement about Firestore
where clause limitations is true?Attempts:
2 left
💡 Hint
Think about Firestore indexing and query constraints.
✗ Incorrect
Firestore requires indexes for combining where and orderBy on different fields. Multiple inequality filters on different fields are not allowed. OR logic is not supported directly. '!=' operator is limited.
🔧 Debug
expert3:00remaining
Debugging a Firestore query with multiple where clauses
You run this query:
What will happen when you run it?
db.collection('employees').where('department', '==', 'sales').where('age', '<', 30).where('age', '>', 40).get()What will happen when you run it?
Attempts:
2 left
💡 Hint
Check Firestore rules about multiple inequality filters on the same field.
✗ Incorrect
Firestore allows multiple inequality filters on the same field. The conditions age < 30 AND age > 40 cannot both be true, so the query returns no documents.