0
0
Firebasecloud~10 mins

Cursor-based pagination (startAfter, endBefore) 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 start the query after the last document.

Firebase
query = collectionRef.orderBy('timestamp').[1](lastDoc)
Drag options to blanks, or click blank then click option'
AstartAfter
BstartAt
CendBefore
DendAt
Attempts:
3 left
💡 Hint
Common Mistakes
Using startAt instead of startAfter causes the query to include the last document again.
Using endBefore or endAt will limit the query to documents before the cursor.
2fill in blank
medium

Complete the code to end the query before the first document.

Firebase
query = collectionRef.orderBy('timestamp').[1](firstDoc)
Drag options to blanks, or click blank then click option'
AstartAfter
BstartAt
CendBefore
DendAt
Attempts:
3 left
💡 Hint
Common Mistakes
Using endAt includes the document, which is not desired here.
Using startAfter or startAt affects the start of the query, not the end.
3fill in blank
hard

Fix the error in the code to correctly paginate starting after a document.

Firebase
query = collectionRef.orderBy('timestamp').[1](lastDoc)
Drag options to blanks, or click blank then click option'
AstartAt
BendAt
CendBefore
DstartAfter
Attempts:
3 left
💡 Hint
Common Mistakes
Passing only the document ID instead of the document snapshot.
Using startAt instead of startAfter causes duplicate results.
4fill in blank
hard

Fill both blanks to paginate between two cursors correctly.

Firebase
query = collectionRef.orderBy('timestamp').[1](startDoc).[2](endDoc)
Drag options to blanks, or click blank then click option'
AstartAfter
BstartAt
CendBefore
DendAt
Attempts:
3 left
💡 Hint
Common Mistakes
Using startAt or endAt includes the cursor documents, causing overlap.
Reversing the order of methods causes unexpected results.
5fill in blank
hard

Fill all three blanks to create a paginated query with limit and cursors.

Firebase
query = collectionRef.orderBy('timestamp').[1](cursorDoc).limit([2]).[3]()
Drag options to blanks, or click blank then click option'
AstartAfter
B10
Cget
Dlimit
Attempts:
3 left
💡 Hint
Common Mistakes
Using limit() twice or missing the get() call.
Passing a string instead of a number to limit().