Process Flow - In and not-in queries
Start Query
Check Query Type
in query
Match docs
Return docs
End
The query starts by checking if it is an 'in' or 'not-in' query, then matches or excludes documents accordingly, and finally returns the results.
db.collection('users') .where('status', 'in', ['active', 'pending']) .get() .then(snapshot => { // process docs })
| Step | Query Type | Field | Operator | Values | Action | Result |
|---|---|---|---|---|---|---|
| 1 | in | status | in | ['active', 'pending'] | Check each doc's status | Match docs with status 'active' or 'pending' |
| 2 | in | status | in | ['active', 'pending'] | Collect matched docs | Docs with status 'active' or 'pending' collected |
| 3 | not-in | status | not-in | ['inactive', 'banned'] | Check each doc's status | Exclude docs with status 'inactive' or 'banned' |
| 4 | not-in | status | not-in | ['inactive', 'banned'] | Collect remaining docs | Docs without status 'inactive' or 'banned' collected |
| 5 | end | - | - | - | Return final docs | Query complete, results returned |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|---|---|
| matchedDocs | [] | ['doc1', 'doc3'] | ['doc1', 'doc3'] | - | - | ['doc1', 'doc3'] |
| excludedDocs | [] | - | - | ['doc2', 'doc4'] | ['doc2', 'doc4'] | ['doc2', 'doc4'] |
| finalDocs | [] | - | - | - | - | ['doc1', 'doc3'] or ['doc1', 'doc3', 'doc5'] depending on query |
Firebase 'in' and 'not-in' queries filter documents by matching or excluding specific field values. Use 'in' to get docs with any value in a list. Use 'not-in' to exclude docs with values in a list. Only one 'in' or 'not-in' filter per query is allowed. Results are returned after filtering documents accordingly.
What does the in query do in Firebase Firestore?
in queryin query checks if a field's value matches any value from a list of values.in.in query = matches any value in list [OK]Which of the following is the correct syntax for a not-in query in Firestore?
db.collection('users').where('age', ___, [18, 21, 25])Given this Firestore query:
db.collection('products').where('category', 'in', ['books', 'games']).get()Which documents will be returned?
What is wrong with this Firestore query?
db.collection('orders').where('status', 'not-in', ['shipped', 'delivered', 'pending', 'cancelled', 'new', 'processing', 'confirmed', 'refunded', 'returned', 'failed', 'on_hold']).get()It throws an error. Why?
You want to find all users whose role is neither 'admin' nor 'moderator' nor 'guest'. Which Firestore query is correct?
Pass the test and this pattern moves unknown