Home > Mobile >  Firebase listener doesn't trigger when collection size is too big
Firebase listener doesn't trigger when collection size is too big

Time:02-03

_firestoreDb.Collection(collectionPath).Listen(callback);

When I listen to a collection that contains a few (hundreds) documents, the listener works fine. However, when the collection starts getting bulky (over 30-40k), it never triggers the callback. Neither the 'initial call' nor when a creation/deletion happens.

CollectionGroup seems to have the same behavior.

Is there any size limit on query listeners? I haven't found any mention on Firebase documentation.

CodePudding user response:

When I listen to a collection that contains a few (hundreds) documents, the listener works fine.

That's the expected behavior.

However when the collection starts getting bulky (over 30-40k), it never triggers the callback.

That's also the expected behavior since reading that amount of data takes a long long time. Besides that, it's also very costly, since everything in Firestore it's about the number of reads and writes you perform.

Reading 30-40k documents at once can be considered an enormous amount of data. Besides that, I don't think that somebody will ever be interested in reading all that data. So the best option that you have is to limit the number of documents your read.

Besides that, the most common approach would be to always read the exact number of documents that you display on the screen. That being said, you should consider getting data in smaller chunks. Most likely 10-20 documents. You can also consider implementing pagination if your app's use case requires it.

  •  Tags:  
  • Related