0
0
Firebasecloud~20 mins

In and not-in queries in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firestore Query Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2: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?

db.collection('products').where('category', 'in', ['electronics', 'books']).get()

Choose the correct description of the query result.
ADocuments where 'category' is not 'electronics' or 'books'.
BDocuments where 'category' is both 'electronics' and 'books' at the same time.
CDocuments where 'category' is exactly the array ['electronics', 'books'].
DDocuments where 'category' is either 'electronics' or 'books'.
Attempts:
2 left
💡 Hint
Think about how 'in' works as a filter for multiple possible values.
service_behavior
intermediate
2: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?

db.collection('users').where('status', 'not-in', ['active', 'pending', 'banned', 'deleted', 'archived', 'new', 'verified', 'suspended', 'guest', 'admin', 'moderator']).get()

Choose the correct outcome.
AThe query will fail with an error about too many values in 'not-in'.
BThe query will return all documents except those with the listed statuses.
CThe query will ignore extra values and only use the first 10.
DThe query will return no documents because 'not-in' does not support arrays.
Attempts:
2 left
💡 Hint
Check Firestore's documented limits on 'in' and 'not-in' queries.
Architecture
advanced
2: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?
AAdd a boolean field 'isValid' and query where 'isValid' is true.
BRun multiple queries for each status and merge results client-side.
CUse a 'not-in' query with the array ['cancelled', 'returned', 'failed'].
DUse a 'where' query with '!=' operator for each status combined with 'or'.
Attempts:
2 left
💡 Hint
Consider Firestore's support for 'not-in' with up to 10 values.
security
advanced
2: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?
AThe 'in' query exposes all documents regardless of security rules.
BUsers might query too many values causing denial of service by exhausting Firestore limits.
CUsers can modify documents directly through the 'in' query.
DThere is no security risk because Firestore automatically filters queries.
Attempts:
2 left
💡 Hint
Think about how query complexity affects backend resources.
🧠 Conceptual
expert
2: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?
ABecause both filters exclude values and combining them creates conflicting conditions Firestore cannot resolve.
BBecause Firestore only supports one filter per field in any query.
CBecause '!=' filters are deprecated and replaced by 'not-in' queries.
DBecause combining these filters would return all documents, making the query pointless.
Attempts:
2 left
💡 Hint
Firestore does not allow multiple filters on the same field.