Challenge - 5 Problems
Firestore Query Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate2:00remaining
What is the result of this Firestore 'in' query?
Consider a Firestore collection 'products' with documents having a field 'category'. What will this query return?
Choose the correct description of the query result.
db.collection('products').where('category', 'in', ['electronics', 'books']).get()Choose the correct description of the query result.
Attempts:
2 left
💡 Hint
Think about how 'in' works as a filter for multiple possible values.
✗ Incorrect
The 'in' query returns documents where the field matches any value in the given array. It does not require the field to match all values or be an array itself.
❓ service_behavior
intermediate2:00remaining
What happens if you use 'not-in' with more than 10 values in Firestore?
Firestore limits the number of values in 'in' and 'not-in' queries. What will happen if you run this query?
Choose the correct outcome.
db.collection('users').where('status', 'not-in', ['active', 'pending', 'banned', 'deleted', 'archived', 'new', 'verified', 'suspended', 'guest', 'admin', 'moderator']).get()Choose the correct outcome.
Attempts:
2 left
💡 Hint
Check Firestore's documented limits on 'in' and 'not-in' queries.
✗ Incorrect
Firestore limits 'in' and 'not-in' queries to a maximum of 10 values. Exceeding this causes an error.
❓ Architecture
advanced2:00remaining
How to efficiently query documents excluding multiple values in Firestore?
You want to get all documents from 'orders' collection where 'status' is not any of ['cancelled', 'returned', 'failed']. Which approach is best to handle this in Firestore given its query limitations?
Attempts:
2 left
💡 Hint
Consider Firestore's support for 'not-in' with up to 10 values.
✗ Incorrect
Firestore supports 'not-in' queries with up to 10 values, so using 'not-in' with these three statuses is efficient and simple.
❓ security
advanced2:00remaining
What security risk arises from using 'in' queries with user input in Firestore?
If you allow users to provide an array of values for an 'in' query on a Firestore collection, what is a potential security concern?
Attempts:
2 left
💡 Hint
Think about how query complexity affects backend resources.
✗ Incorrect
Allowing users to input large arrays for 'in' queries can cause performance issues or errors due to Firestore's limits, potentially leading to denial of service.
🧠 Conceptual
expert2:00remaining
Why can't Firestore 'not-in' queries be combined with '!=' filters on the same field?
Firestore does not allow combining 'not-in' and '!=' filters on the same field in a single query. Why is this restriction in place?
Attempts:
2 left
💡 Hint
Firestore does not allow multiple filters on the same field.
✗ Incorrect
Firestore only supports one filter per field in any query. You cannot combine multiple filters like 'not-in' and '!=' on the same field.