0
0
Firebasecloud~10 mins

Query optimization 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 Firestore query that orders documents by the 'timestamp' field.

Firebase
const query = firestore.collection('messages').orderBy('[1]');
Drag options to blanks, or click blank then click option'
Atimestamp
Bname
Cage
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Using a field that does not exist in the collection.
Forgetting to specify the field name as a string.
2fill in blank
medium

Complete the code to limit the number of documents returned by the query to 10.

Firebase
const limitedQuery = query.[1](10);
Drag options to blanks, or click blank then click option'
Afilter
BstartAt
CorderBy
Dlimit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'filter' instead of 'limit' to restrict results.
Confusing 'orderBy' with limiting results.
3fill in blank
hard

Fix the error in the query to filter documents where 'status' equals 'active'.

Firebase
const activeQuery = firestore.collection('users').where('status', '[1]', 'active');
Drag options to blanks, or click blank then click option'
A==
B=
Cis
Dequals
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' in the where clause.
Using non-supported operators like 'equals' or 'is'.
4fill in blank
hard

Fill both blanks to create a query that filters documents where 'age' is greater than 18 and orders by 'age'.

Firebase
const adultQuery = firestore.collection('users').where('age', '[1]', 18).[2]('age');
Drag options to blanks, or click blank then click option'
A>
B<
CorderBy
Dlimit
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for filtering ages.
Using 'limit' instead of 'orderBy' to sort results.
5fill in blank
hard

Fill all three blanks to create a query that filters documents where 'score' is at least 50, orders by 'score', and limits results to 5.

Firebase
const topScores = firestore.collection('games').where('score', '[1]', 50).[2]('score').[3](5);
Drag options to blanks, or click blank then click option'
A>=
BorderBy
Climit
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>=' for filtering scores.
Mixing up the order of 'orderBy' and 'limit' methods.