Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
startAfter function always display the same data

I'm beginner to firestore. My query always give the same data independently of the value i pass into startAfter() function.

here's code:

    const fetchMore = async () => {
        const q = query(
            collection(db, 'chat-messages'),
            orderBy('createdAt', 'asc'),
            startAfter(23),
            limit(5),
        );

        const querySnapshot = await getDocs(q)

        querySnapshot.forEach(doc => {
            console.log(doc.data())
        })
    }

Thanks for reading and helping! Have a nice day

enter image description here

here's the console.log

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I'm not sure what type the data in your startAt field is, but I guess it's a date or a Firestore Timestamp.

Pagination in Firestore is not based on numeric offsets, as you may be used to from other databases, but instead is based on so-called cursor objects: knowing the values and/or ID of the document you want to start after.

So you'll need to pass in the timestamp that you want to start after, not the number of documents you want to skip. So for example, to get all documents with a createdAt after now, you could do:

startAfter(Timestamp.now())

For more on this way of pagination, see the documentation on paginating data with query cursors.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!