0
0
Firebasecloud~20 mins

Query limitations and workarounds 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!
🧠 Conceptual
intermediate
2:00remaining
Understanding Firestore Query Limitations

Firestore queries have some limitations. Which of the following is NOT a Firestore query limitation?

AYou cannot perform a query with multiple inequality filters on different fields.
BYou cannot perform a query that combines 'OR' conditions directly.
CYou cannot query documents without an index on the queried fields.
DYou cannot order query results by a field that is not included in the filters.
Attempts:
2 left
💡 Hint

Think about what Firestore allows in ordering and filtering.

Architecture
intermediate
2:00remaining
Workaround for Firestore 'OR' Queries

You want to query documents where status is 'active' OR priority is 'high'. Firestore does not support 'OR' queries directly. Which approach correctly implements this?

APerform two separate queries and merge results in the client.
BUse a single query with multiple inequality filters on both fields.
CCreate a composite field combining status and priority and query on it.
DUse Firestore's 'array-contains-any' operator on both fields.
Attempts:
2 left
💡 Hint

Consider how Firestore handles multiple queries and client-side merging.

Configuration
advanced
2:00remaining
Index Configuration for Complex Queries

You have a Firestore query filtering by category and ordering by timestamp. The query fails due to missing index. Which index configuration is required?

Firebase
collection: products
fields:
  - fieldPath: category
    order: ASCENDING
  - fieldPath: timestamp
    order: DESCENDING
AAn index on category ascending and timestamp descending.
BAn index on timestamp ascending only.
CAn index on category descending and timestamp ascending.
DNo index needed; Firestore supports this query by default.
Attempts:
2 left
💡 Hint

Check the order directions in the query and index.

service_behavior
advanced
2:00remaining
Behavior of Firestore Queries with Inequality Filters

What happens if you try to run a Firestore query with inequality filters on two different fields, for example age > 20 and score < 50?

AThe query runs successfully and returns matching documents.
BThe query fails with an error about multiple inequality filters.
CThe query ignores one of the inequality filters and runs.
DThe query runs but returns no documents.
Attempts:
2 left
💡 Hint

Recall Firestore's rules on inequality filters.

security
expert
3:00remaining
Securing Queries with Firestore Rules and Query Limitations

You want to secure a Firestore collection so users can only read documents where ownerId equals their user ID. You write a security rule using request.auth.uid == resource.data.ownerId. Which query limitation must you consider to ensure the query passes the security rules?

AThe query can omit filtering on <code>ownerId</code> because rules handle security.
BThe query must order by <code>ownerId</code> but not filter on it.
CThe query must include a filter on <code>ownerId</code> equal to the user's ID.
DThe query must use a composite index on <code>ownerId</code> and <code>timestamp</code>.
Attempts:
2 left
💡 Hint

Think about how Firestore security rules interact with queries.