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

123
Views
Firebase 9 Firestore paginate query with setInterval
let lastVisibleSnapshot = 0;
let docQuery;
let myInterval;
const queryLimit = 7; //TODO change limit to less than 500 per second!!!

function myQuery() {

    const queryArgs = [collection(db, "users", UID, "products"), limit(queryLimit)];
    docQuery = (lastVisibleSnapshot == 0) ? query(...queryArgs) : query(...queryArgs, startAfter(lastVisibleSnapshot));

}

async function startReset() {

    myQuery();
    let documentSnapshot = await getDocs(docQuery);
    if (documentSnapshot.empty) {
        console.log("documentSnapshot Empty");
        clearInterval(myInterval);
    } else {
        documentSnapshot.forEach((doc) => {
            console.log(doc.id);
        });
    }
    lastVisibleSnapshot = documentSnapshot.docs[documentSnapshot.docs.length - 1];

}

    myInterval = setInterval(startReset, 1000);

I try to update my Firestore all documents in chunks. The above code works, but I found I shouldn't use interval with async function. Any better solution?

about 4 years ago · Juan Pablo Isaza
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!