0
0
Firebasecloud~20 mins

Limit and pagination in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firestore Pagination Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
1: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;
A10
B0
C5
DThrows an error
Attempts:
2 left
💡 Hint
Think about what the limit function does in Firestore queries.
Architecture
intermediate
2: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?
AUse <code>limit()</code> with <code>offset()</code> to skip documents
BUse <code>limit()</code> with <code>startAfter()</code> using the last document snapshot
CFetch all documents and slice the array in the client
DUse <code>limit()</code> with <code>where()</code> filtering by document ID
Attempts:
2 left
💡 Hint
Consider how Firestore handles offsets and document snapshots.
Configuration
advanced
2: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]);
Afirestore.collection('items').limit(3).startAfter(lastDoc).get()
Bfirestore.collection('items').orderBy('createdAt').startAt(lastDoc).limit(3).get()
Cfirestore.collection('items').orderBy('createdAt').offset(3).limit(3).get()
Dfirestore.collection('items').orderBy('createdAt').startAfter(lastDoc).limit(3).get()
Attempts:
2 left
💡 Hint
Remember the difference between startAfter and startAt.
security
advanced
2: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?
Amatch /items/{itemId} { allow read: if request.auth.uid == resource.data.ownerId; }
Bmatch /items/{itemId} { allow read: if request.auth.uid != resource.data.ownerId; }
Cmatch /items/{itemId} { allow read: if true; }
Dmatch /items/{itemId} { allow read: if request.auth == null; }
Attempts:
2 left
💡 Hint
Think about how to restrict access to only the document owner.
🧠 Conceptual
expert
2:30remaining
Impact of Using Offset in Firestore Pagination
What is the main drawback of using offset() for pagination in Firestore compared to startAfter()?
AOffset causes Firestore to read and discard skipped documents, increasing cost and latency
BOffset automatically caches documents, reducing read costs
COffset guarantees no documents are skipped or repeated
DOffset is faster than startAfter because it uses indexes
Attempts:
2 left
💡 Hint
Consider how Firestore processes offset internally.