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?