Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to read data efficiently from Firebase.
Firebase
const docRef = db.collection('users').doc([1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using collection name instead of document ID
Calling get() inside doc()
✗ Incorrect
We need to specify the exact document ID to read efficiently, so 'userId123' is correct.
2fill in blank
mediumComplete the code to fetch only the needed fields from a document.
Firebase
docRef.get().then(snapshot => { const data = snapshot.[1](); }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using get() instead of data() on snapshot
Trying to fetch fields directly without calling data()
✗ Incorrect
The method to get document data from a snapshot is data().
3fill in blank
hardFix the error in the query to limit reads to 10 documents.
Firebase
db.collection('posts').[1](10).get();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() which does not exist
Using where() without conditions
Using orderBy() without limit()
✗ Incorrect
The correct method to limit the number of documents read is limit().
4fill in blank
hardFill both blanks to create a query that reads only active users and limits to 5 results.
Firebase
db.collection('users').[1]('status', '==', 'active').[2](5).get();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() which is not a Firebase method
Swapping limit() and where() order
✗ Incorrect
Use where() to filter active users and limit() to restrict to 5 reads.
5fill in blank
hardFill all three blanks to read documents ordered by timestamp, filtered by type, and limited to 3.
Firebase
db.collection('events').[1]('type', '==', 'click').[2]('timestamp').[3](3).get();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() instead of where()
Changing the order of method calls
Omitting limit() causing too many reads
✗ Incorrect
Use where() to filter by type, orderBy() to sort by timestamp, and limit() to restrict reads.