It is known that firebase bills with number of doc reads. there is a daily limit to firestore doc read (50k read per day). but when i fetch in my react app it prompts the quota exceed error.
FirebaseError: Request failed with error: Quota exceeded.
what i actually did was i created an async function to get documents, and called it. but this way it listens to every change in firestore, and read all over again. i haven't even opened the console b/c it listens to changes as well.
let me explain what i'm building. I'm building an amazon type web. and in the home page it display the products. so to prevent more read i need to limit the number of fetched docs. initially, the first items fetched should be 21 products. and when the user reach the end of the list they click the load more button and it loads an additional 21 products.
so my questions are, How can i Limit the number of docs fetched? even if it's limited does it cache the previously loaded docs or it reloads them again? and if i use snapshot listener does that reload every docs or updates the latest one? is there a right way to fetch firestore documents?
this is how i used it
const getData = async () => {
const constraints = [];
if (price)
constraints.push(orderBy("price", price == "1" ? "desc" : "asc"));
if (date)
constraints.push(orderBy("postedDate", date == "1" ? "desc" : "asc"));
const livings = collection(db, "livingPosts");
let q = query(livings, ...constraints);
const qSnapshot = await getDocs(q);
const dataQ = qSnapshot.docs.map((doc) => ({
...doc.data(),
id: doc.id,
}));
// console.log(dataQ);
setDatas(dataQ);
};
getData();