0
0
Firebasecloud~10 mins

Collection group queries in Firebase - Interactive Code Practice

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

Complete the code to create a collection group query for all 'messages' collections.

Firebase
const query = firestore.collectionGroup('[1]');
Drag options to blanks, or click blank then click option'
Ausers
Bcomments
Cmessages
Dposts
Attempts:
3 left
💡 Hint
Common Mistakes
Using a top-level collection name instead of the subcollection name.
Misspelling the collection name.
2fill in blank
medium

Complete the code to add a filter where the 'status' field equals 'active' in the collection group query.

Firebase
const activeMessages = firestore.collectionGroup('messages').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
Using the wrong status string.
Forgetting quotes around the string value.
3fill in blank
hard

Fix the error in the code by completing the method to get the query results.

Firebase
const snapshot = await firestore.collectionGroup('messages').[1]();
Drag options to blanks, or click blank then click option'
Aget
Bretrieve
Cload
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'fetch' or 'retrieve'.
Omitting the parentheses after the method name.
4fill in blank
hard

Fill both blanks to create a query that orders messages by 'timestamp' descending and limits to 10 results.

Firebase
const recentMessages = firestore.collectionGroup('messages').orderBy('[1]', '[2]').limit(10);
Drag options to blanks, or click blank then click option'
Atimestamp
Basc
Cdesc
DcreatedAt
Attempts:
3 left
💡 Hint
Common Mistakes
Using ascending order instead of descending.
Using the wrong field name for ordering.
5fill in blank
hard

Fill all three blanks to create a query that filters messages with 'read' equal to false, orders by 'timestamp' ascending, and limits to 5 results.

Firebase
const unreadMessages = firestore.collectionGroup('[1]').where('[2]', '==', [3]).orderBy('timestamp', 'asc').limit(5);
Drag options to blanks, or click blank then click option'
Amessages
Bread
CFalse
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'true' instead of 'false' for unread messages.
Using the wrong collection group name.