0
0
Firebasecloud~10 mins

Array-contains 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 query documents where the 'tags' array contains 'cloud'.

Firebase
const query = firestore.collection('articles').where('tags', '[1]', 'cloud');
Drag options to blanks, or click blank then click option'
Aarray-contains
B==
Cin
Darray-contains-any
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'array-contains' for array fields.
Using 'in' which checks for values in a list, not inside arrays.
2fill in blank
medium

Complete the code to query documents where the 'categories' array contains any of the values in ['tech', 'science'].

Firebase
const query = firestore.collection('posts').where('categories', '[1]', ['tech', 'science']);
Drag options to blanks, or click blank then click option'
Aarray-contains-any
Bin
Carray-contains
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'array-contains' which only checks for one value.
Using 'in' which checks if a field equals any value in a list, not array contents.
3fill in blank
hard

Fix the error in the query to find documents where 'skills' array contains 'firebase'.

Firebase
const query = firestore.collection('users').where('skills', '[1]', 'firebase');
Drag options to blanks, or click blank then click option'
A==
Barray-contains-any
Cin
Darray-contains
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which does not work for array fields.
Using 'in' which is for matching field values, not array contents.
4fill in blank
hard

Fill both blanks to query documents where the 'features' array contains any of the values ['fast', 'reliable'], and limit to 5 results.

Firebase
const query = firestore.collection('products').where('features', '[1]', ['fast', 'reliable']).limit([2]);
Drag options to blanks, or click blank then click option'
Aarray-contains-any
Barray-contains
C5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'array-contains' which only accepts a single value, not an array.
Not setting a limit or using an invalid limit value.
5fill in blank
hard

Fill all three blanks to query documents where 'tags' array contains 'cloud', order by 'date', and limit to 3 results.

Firebase
const query = firestore.collection('events').where('tags', '[1]', 'cloud').orderBy('[2]').limit([3]);
Drag options to blanks, or click blank then click option'
Aarray-contains
Bdate
C3
Dtimestamp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'array-contains-any' when only one value is needed.
Ordering by a wrong field name.
Setting an invalid limit number.