0
0
Firebasecloud~10 mins

Getting all documents in collection 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 get a reference to the collection named 'users'.

Firebase
const usersCollection = firestore.collection([1]);
Drag options to blanks, or click blank then click option'
A"users"
Busers
C'user'
D'users'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the collection name.
Using the wrong collection name.
2fill in blank
medium

Complete the code to fetch all documents from the 'users' collection.

Firebase
const snapshot = await usersCollection.[1]();
Drag options to blanks, or click blank then click option'
Aget
Bfetch
Cretrieve
DgetDocs
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'getDocs' which is from Firebase v9 modular syntax, not the older syntax.
Using 'fetch' which is not a Firestore method.
3fill in blank
hard

Fix the error in the code to loop through all documents in the snapshot.

Firebase
snapshot.forEach(doc => [1](doc.data()));
Drag options to blanks, or click blank then click option'
Aprint
Blog
Cconsole.log
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' which is not a JavaScript function.
Using 'log' without 'console'.
4fill in blank
hard

Fill both blanks to create a map of document IDs to their data.

Firebase
const dataMap = {};
snapshot.forEach(doc => {
  dataMap[doc.[1]] = doc.[2]();
});
Drag options to blanks, or click blank then click option'
Aid
Bdata
CgetId
DgetData
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like 'getId' or 'getData' which do not exist.
Confusing properties and methods.
5fill in blank
hard

Fill all three blanks to filter documents with age greater than 18 and map their names.

Firebase
const adults = snapshot.docs
  .filter(doc => doc.data().[1] [2] [3])
  .map(doc => doc.data().name);
Drag options to blanks, or click blank then click option'
Aage
B>
C18
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong field name.
Using the wrong comparison operator.