Challenge - 5 Problems
Firestore Pagination Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate1:30remaining
Understanding Firestore Query Limit Behavior
You run a Firestore query with
limit(5) on a collection with 10 documents. What will be the number of documents returned?Firebase
const querySnapshot = await firestore.collection('users').limit(5).get(); const count = querySnapshot.size;
Attempts:
2 left
💡 Hint
Think about what the limit function does in Firestore queries.
✗ Incorrect
The limit function restricts the number of documents returned to the specified number, here 5, even if more documents exist.
❓ Architecture
intermediate2:00remaining
Choosing Pagination Strategy in Firestore
You want to paginate through a large Firestore collection efficiently. Which approach is best to avoid skipping or repeating documents?
Attempts:
2 left
💡 Hint
Consider how Firestore handles offsets and document snapshots.
✗ Incorrect
Using
startAfter() with the last document snapshot is efficient and avoids skipping or repeating documents unlike offset() which can be costly.❓ Configuration
advanced2:30remaining
Correct Firestore Query for Pagination with Limit
Which Firestore query correctly fetches the next 3 documents after a given document snapshot
lastDoc?Firebase
const lastDoc = await firestore.collection('items').orderBy('createdAt').limit(3).get().then(snap => snap.docs[2]);
Attempts:
2 left
💡 Hint
Remember the difference between startAfter and startAt.
✗ Incorrect
startAfter(lastDoc) skips the last document and fetches the next set. startAt includes the lastDoc again causing overlap.
❓ security
advanced2:00remaining
Securing Paginated Firestore Queries
You want to ensure users can only paginate through their own documents in Firestore. Which security rule correctly enforces this?
Attempts:
2 left
💡 Hint
Think about how to restrict access to only the document owner.
✗ Incorrect
The rule allows read only if the authenticated user's ID matches the document's ownerId field, securing pagination to user-owned docs.
🧠 Conceptual
expert2:30remaining
Impact of Using Offset in Firestore Pagination
What is the main drawback of using
offset() for pagination in Firestore compared to startAfter()?Attempts:
2 left
💡 Hint
Consider how Firestore processes offset internally.
✗ Incorrect
Offset makes Firestore read all skipped documents internally, which increases read operations and latency, unlike startAfter which uses document snapshots.