0

I am well aware of real-time database querying limitation, but I thought might seek help from others, basically what I'm trying to do is paginate the search result of a query, let's say we search for users with the name "motahir" and we have 100 results, I want to show the first 20 results and when the user scrolls down then retrieve the second 20 results, one possible trick is to download the whole results (all 100 records) and show only 20 and then add the rest of the result as the user scrolls down but this is inefficient, another trick is to limit the results to first 20 and when we want the next 20 records, we run a query to retrieve the first 40 records, the first 20 records of the 40 records that we've retrieved are duplicate, again this is inefficient, we'll have to download the previous set of data every time we want to retrieve a new 20 records.

it won't be a good idea to download the whole records as well, what if we had 1000 records with the name "motahir".

so any ideas of how to solve this problem?

MoTahir
  • 863
  • 7
  • 22
  • which field you're gonna use for orderBy ? – Ashish Jul 03 '19 at 11:41
  • since I'm searching using the name of the user then I must use the username field. I can't use the "startAt" because I am querying based on the name and all of the records that I'm retrieving have the same username – MoTahir Jul 03 '19 at 11:45
  • cause pagination you need to put orderby for retrieve data it needs to be in any order like i used `created_at` to get proper list – Ashish Jul 03 '19 at 11:56
  • yes I am using order by and I've done pagination before, but I want to know how to paginate a queried data. – MoTahir Jul 03 '19 at 12:20
  • [Alex Mamo](https://stackoverflow.com/users/5246885/alex-mamo) already provided in one of his [answer](https://stackoverflow.com/questions/50741958/how-to-paginate-firestore-with-android) how to paginate with firebase – Ashish Jul 03 '19 at 12:22
  • Alex Mamo's answer isn't queried, if the data that I'm retrieving isn't queried it would be simple, you just get the key of the node then start getting the data after that node but this isn't the case here, I have to query the data first then select the next 20 records.. – MoTahir Jul 03 '19 at 12:29
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/195930/discussion-between-ashish-and-motahir). – Ashish Jul 03 '19 at 12:36

0 Answers0