0
0
GCPcloud~10 mins

Firestore queries and indexes in GCP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to query Firestore for documents where the field 'status' equals 'active'.

GCP
query = firestore_client.collection('users').where('status', '==', [1])
Drag options to blanks, or click blank then click option'
A'inactive'
B'active'
C'pending'
D'deleted'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around string values
Using wrong comparison operator
2fill in blank
medium

Complete the code to order Firestore query results by the 'createdAt' timestamp in descending order.

GCP
query = firestore_client.collection('orders').order_by('createdAt', [1])
Drag options to blanks, or click blank then click option'
Adesc
Basc
Cascending
Ddescending
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ascending' or 'descending' instead of 'asc' or 'desc'
Reversing order direction
3fill in blank
hard

Fix the error in the Firestore query to filter documents where 'age' is greater than 18.

GCP
query = firestore_client.collection('users').where('age', [1], 18)
Drag options to blanks, or click blank then click option'
A>
B<=
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>'
Using '<=' which filters wrong range
4fill in blank
hard

Fill both blanks to create a Firestore composite index query filtering 'category' equals 'books' and ordering by 'price' ascending.

GCP
query = firestore_client.collection('products').where('category', '==', [1]).order_by('price', [2])
Drag options to blanks, or click blank then click option'
A'books'
B'electronics'
Casc
Ddesc
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong category value
Ordering price descending instead of ascending
5fill in blank
hard

Fill all three blanks to create a Firestore query that filters documents where 'status' is 'active', 'priority' is greater than 3, and orders by 'dueDate' descending.

GCP
query = firestore_client.collection('tasks').where('status', '==', [1]).where('priority', [2], 3).order_by('dueDate', [3])
Drag options to blanks, or click blank then click option'
A'active'
B>
Cdesc
Dasc
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operators
Ordering dueDate ascending instead of descending