Bird
0
0

How can you model a Firestore document to efficiently query users by multiple roles, where each user can have zero or more roles?

hard📝 Application Q9 of 15
GCP - Cloud Firestore and Bigtable
How can you model a Firestore document to efficiently query users by multiple roles, where each user can have zero or more roles?
AUse an array field to store roles and query with array-contains
BCreate a separate collection for roles with user IDs as documents
CStore roles as a comma-separated string in a single field
DUse nested maps with role names as keys and booleans as values
Step-by-Step Solution
Solution:
  1. Step 1: Understand querying by multiple roles

    Firestore supports querying array fields with array-contains to find documents with a specific value.
  2. Step 2: Evaluate modeling options

    Using an array field for roles allows simple queries and flexible role assignment.
  3. Final Answer:

    Use an array field to store roles and query with array-contains -> Option A
  4. Quick Check:

    Array fields enable efficient multi-value queries [OK]
Quick Trick: Store multi-values in arrays for easy querying [OK]
Common Mistakes:
  • Using strings instead of arrays
  • Overcomplicating with separate collections
  • Using maps that are hard to query

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes