Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use onSnapshot with pagination in firestore

I have created a todo list web app using firestore ,where each todo item is stored as a document , Queries i want to perform :

  1. Add a todo item to firestore
  2. Delete a todo item
  3. Get real time updates of todo items

I am able to do this but the issue here is i am getting all the documents returned by the query, but now i want to limit the data , and get more data when user reach end of current data while getting the updates in real time(for old fetched data like any content change in documents above)

Some ways i can think of is

  1. Create a new listener for every new batch (and when a document is created all the data below that batch )
  2. Increase the limit for every batch and get all data from begining.

which will be more efficient ? also if there is any other way please let me know

like image 754
Task Avatar asked Dec 28 '25 22:12

Task


1 Answers

"Add a todo item to Firestore" and "Delete a todo item" are not queries, are just operations to add and delete documents to/from Firestore.

Get real-time updates of to-do items.

When it comes to reading data from Firestore, please note that as a collection gets larger your bill will be larger too. So you should always limit the data you read. If you want to read the data progressively, meaning reading data in smaller chunks then I recommend you implement pagination. While real-time pagination can be implemented, I recommend against it, since it can produce many reads. So I recommend you only use get() for paginating the results.

like image 116
Alex Mamo Avatar answered Dec 31 '25 23:12

Alex Mamo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!