reading from firebase for Realtime updates without exceeding quota

83 views Asked by At

I am trying to read from firebase to get real-time updates from the database.

    useEffect(() =>
        onSnapshot(collection(db, 'announcements'), async (snapshot) => {
            let oldData = announcementsData;
            let temp = snapshot.docs.map(doc => doc.data());
            // sort temp by id in descending order
            temp.sort((a, b) => {
                return b.id - a.id;
            }
            );
            // console.log(oldData.length !== temp.length && oldData.length !== 0, oldData.length, temp.length, announcementsData);

            if (oldData.length !== temp.length && oldData.length !== 0) {
                await schedulePushNotification(temp[0].title, temp[0].description);
            }
            setAnnouncementsData(temp);

        })
        , [announcementsData]);

This is how I am fetching data. What I think I am doing it gets a a snapshot of the db, I have been told this doesn't count as read. But it still did exceed the quota. Can anyone tell how to keep checking database for updates without exceeding the quota.

0

There are 0 answers