Home > Enterprise >  FirebaseError: Quota exceeded :How to shut down snapShot listener Firebase
FirebaseError: Quota exceeded :How to shut down snapShot listener Firebase

Time:09-21

I'm building a small chat app with expo, connected to Firestore. Here is the code to fetch the chat data:

useEffect(() => {
    console.log("Loading snapShots on firebase");
   const unsubscribe = db.collection('chats').onSnapshot(snapshot => (
        setChats(snapshot.docs.map(doc => ({
            id: doc.id,
            data: doc.data()
        })))
    ))
    setTimeout(()=>{
         unsubscribe();
    }, 1000);

}, [])

This code is normally if I followed correctly documentation, supposed to close the snapShot listener after one second. If it does, I still get a [FirebaseError: Quota exceeded.] message and my app is very small, the data too.

CodePudding user response:

Firebase quotas are reset daily at midnight (Pacific time). According to your timezone, it may differ. If you're located in Europe, it actually may be in the middle of the day. So if you reach the daily limitation, there is nothing you can do, but wait until the "next" day. Or you can update to the Spark Plan.

But remember, once you got the quota exceeded message your project will not be accessible until the quotas are reset.

As also @Dharmaraj mentioned in his comment, you might also consider using a get() call, and not listen for real-time changes. In this way, you attach a listener that is discounted automatically once you got the data.

Please also remember to not keeping your Firebase console open, as it is considered another Firestore client that reads data. So you'll be also billed for the reads that are coming from the console.

  • Related