How Do I Paginate My Data? | Get to know Cloud Firestore #7

Поділитися
Вставка
  • Опубліковано 17 січ 2025

КОМЕНТАРІ • 145

  • @NicoloZanetti
    @NicoloZanetti 5 років тому +3

    Amazing course, good job Todd and Firebase crew! I watched all 7 videos published so far in a single morning and I don't feel lost anymore!

  • @luiswebdev8292
    @luiswebdev8292 2 роки тому +8

    these videos are really really good and instructional, thanks for them

    • @Firebase
      @Firebase  2 роки тому +6

      Thank you for the feedback! We aim to provide quality content 😎

  • @kingsleyforbes-smith2141
    @kingsleyforbes-smith2141 5 років тому +5

    Brilliant, and answers real questions with real limitations (eg costs) , please keep creating.

  • @d4lep0ro
    @d4lep0ro 3 роки тому +5

    Remember that incremental (limit) pagination breaks if you have persistence on, queries might trigger from old cached values. Say you query for 10 elements, you might get 2 element from older cache.

  • @nawaralsafar508
    @nawaralsafar508 5 років тому +4

    The Firestore videos series is awesome. Its nice to have a cool dude make you laugh while you learn about underlying technology. Great content and very helpful. Keep sharing please :D ;)

  • @j.guillaumed-isabelle2237
    @j.guillaumed-isabelle2237 5 років тому +7

    I loved this gummy big bear intro haha

  • @Bigjunior987
    @Bigjunior987 5 років тому +31

    If I increase the limit from 20 to 40 to 60, do I really fetch also the first 20 documents all the time?
    I thought that the Firestore client SDKs cache these documents and send me those documents only if it's needed.
    Or is it just that I get billed for those, but Firestore tells the client SDK that it already has the most recent version of the first 20 documents?

    • @blessing7695
      @blessing7695 5 років тому

      Great question

    • @joereem
      @joereem 5 років тому +7

      This is something i struggle with as there are just hints in the document of how caching works and when you will benefit from it. I can do tests and sometimes I do to try to figure if a query is expensive, but it would be easier to remember if I could get a lesson on it. Please make this a future topic for an episode or add a section devoted to it in the documentation.

    • @Bigjunior987
      @Bigjunior987 5 років тому +1

      @zztop3000 Yeah I know that Todd says that you are re-requesting the old data, but this confuses me.
      Why should the documents be fetched again? They are already present in the cache of the app.
      Or do I just get billed for those documents even though they don't get sent to the client?

    • @acche-rc
      @acche-rc 5 років тому

      Because offline persistent is not enabled by default everywhere

    • @blizzard182
      @blizzard182 5 років тому +2

      @@ToddKerpelmanCorp One follow up question. If with the offset you are basically just querying and charging for every record up to the offset, then what is the point of having that parameter at all? You could just request all the records with limit and that would be the same. I always thought of it like pagination and avoiding requesting and charging money for these records. This is actually a huge thing that should be in the docs.

  • @codeconcept
    @codeconcept 5 років тому +1

    Some people tend to say awesome for just 'ok' stuff. But this playlist is really... awesome :) The content, the presentation, the animations. Everything is top quality. Keep up the good work!

  • @rubenheymans1988
    @rubenheymans1988 5 років тому +2

    this video is great in explaining the theory behind, but where are the code examples? why is this not in the angularfire docs?

  • @1002CK
    @1002CK 5 років тому +25

    So there is a read charge even clients app cached the same document data

    • @notfound521
      @notfound521 4 роки тому +1

      Yeah that seem really confusing, in the third video of the serie they said just the opposite so what's the truth?

    • @mustafaalnoori5213
      @mustafaalnoori5213 3 роки тому

      I think if you want to make this work you need to read the whole collection with attached listener so when anything changes only the change will count as new read

  • @1002CK
    @1002CK 5 років тому +16

    Another way is order query result by timeStamp descending or ascending, then retrieve document according to document timeStamp

    • @codesnacksIO
      @codesnacksIO 4 роки тому +1

      This is a good input. Wonder why Todd didn't add it

  • @noamgonen6243
    @noamgonen6243 5 років тому +1

    Thx for the simple show of options and associated tradeoffs . PS - where on Earth did you find such a enormous gummy bear? Must have doubled this episode's production costs...

  • @learnings2173
    @learnings2173 2 роки тому +1

    Thanks...very informative

  • @jamieperkins906
    @jamieperkins906 5 років тому +3

    Thanks for this! I would love a video that suggests a schema for commenting on user's posts. It's a little tricky to set it up so it's safe permission wise, but also logical query-wise.

  • @chriscurnow143
    @chriscurnow143 5 років тому +6

    Hey Todd, are you available to do the instructional videos for our app🤣? Seriously, another great video. I haven't got up to thinking about pagination yet but I will soon and this explains pretty much everything I need to know.

  • @MuhammadbinYusrat
    @MuhammadbinYusrat 5 років тому +8

    I don't think Google has ever used Firebase for any of their own project because of how many basic things it seems to lack so casually.

  • @CoryMcaboy
    @CoryMcaboy 5 років тому +2

    It is great to see a video on pagination best practices. Thank you!

  • @erickeft
    @erickeft Рік тому +1

    Thanks. Would be great to have a new video focusing more in pagination for realtime cases, like chat apps, for instance. It's kind of complicated to find help online for a consistent way to implement pagination with real-time updates with Firestore

  • @osmanmusse9432
    @osmanmusse9432 3 роки тому +1

    Best teacher end of story

  • @JulienReszka
    @JulienReszka 4 роки тому +4

    did the api change ? nothing of this works currently

  • @BogacGuven
    @BogacGuven 5 років тому

    Giant gummy bear analogy: spot on.

  • @CardinalHijack
    @CardinalHijack 5 років тому +4

    So this means that conventional pagination (which has a nav containing 1 - total page count) is impossible out of the box with Firebase - the only option is to infinitely scroll pagination as described. I cant believe this is no way to do this easily with Firebase. Think ill bite the bullet and move over to AWS

  • @videoguy640
    @videoguy640 5 років тому +3

    Great outro lol. Any way to order by random order while using pagination? Say if I want to give my user 20 random reviews in each batch?

    • @videoguy640
      @videoguy640 5 років тому

      @@ToddKerpelmanCorp Gotcha, I think I'll end up using a cloud function to periodically update the random fields. Not a perfect solution, but cheaper than other options that I can think of

  • @giuliofederico7638
    @giuliofederico7638 3 роки тому +1

    Brilliant as ever

  • @vitako7714
    @vitako7714 5 років тому

    great video; 2:31; does firestore support query on one field and order by another field now? just wondering if it now supports this what I love to hear or is it just a makeup example to simplify the video? thanks #askfirebase

  • @NanduriBharrath_nb
    @NanduriBharrath_nb 5 років тому +2

    Please make your videos as frequently as possible. It's hard to find good Firestore tutorials or courses online.

    • @NanduriBharrath_nb
      @NanduriBharrath_nb 5 років тому +1

      @@ToddKerpelmanCorp Thanks for writing back!! You are GOOGLE! There's no such thing for you guys that's tough. If you put your will to it.. I guess you'll get it done. Try using softwares like Video Scribe. They are fast and easy to make yet crisp and useful for educational purposes.

  • @jonnyp
    @jonnyp 5 років тому +2

    great video - thanks - would be great to see a result count for the query as well, though I understand it's not easy in firestore

  • @smrtsoftware
    @smrtsoftware 5 років тому

    This pagination this is really cool, not tedious and very efficient. Nice work Google Firebase Team!

  • @juliangzr4998
    @juliangzr4998 3 роки тому +1

    you missed one thing, to paginate without infinite scroll we need to know the amount of records the search has, so we can know the amount of pages, how we can do that?

    • @helmchen1239
      @helmchen1239 3 роки тому +3

      use a proper database ;)

    • @nivaldolemos5280
      @nivaldolemos5280 3 роки тому

      Firestore is crap, specially the web SDK.
      Any supposed gain in productivity vanishes when you reach such simple and common use case.
      In a SQL database, it's terribly simple.

  • @raghav4296
    @raghav4296 5 років тому +1

    Hi Todd, was expecting your video after the GA on the enhancements to Firestore and things to lookout for. Any videos in the making? 🎬

  • @ynonrahamim
    @ynonrahamim Рік тому

    Great explanation! Thanks

  • @MohitAtray
    @MohitAtray 5 років тому +1

    @Todd There is a nice idea for you! What if we can extend range of values to listen to while paginating. For example, I do this query for first 20 docs and listen to it -- [limit: 20]. Then when I reach end while scrolling, I do this another query for next 20 docs [startAfter: , limit: 20]. Now it would be awesome if I could just change the limit of what I was listening to in the 1st batch to 40 or maybe change the "end doc" to listen for changes upto. Not send the request, just change what I am listening to.That way, I will only request for 20 docs (20 reads) in 2nd batch and I would be listening to changes in 1st 40 docs. Problem of realtime updating solved!
    The problem will also be solved if there is a way to just listen to changes in a range of docs without retrieving (requesting for) the docs in the specified range.

    • @ebonilha
      @ebonilha 4 роки тому +1

      This wouldn't work because as he mentioned, the database won't keep the pagination state, so the range [0,40] for a specific query is not something it can do without re-doing the entire query.

  • @pandarzzz
    @pandarzzz 5 років тому +1

    Thank you for sharing this informative video! I hope you are well: Todd & Firebase Team!

  • @thedevguild7525
    @thedevguild7525 2 роки тому

    I believe the key essence here is, the option you choose is dependent on how real-timeliness you want your app to be!!

  • @yeilmusic
    @yeilmusic 3 роки тому +2

    How to count documents without being charged

  • @kenechukwuAkubue
    @kenechukwuAkubue 9 місяців тому

    for the 3rd option, why not check for changes before pulling everything. if there are no updates on the old data its should just pull the new one and merge it with the one it has locally on cache

  • @escoladejesusnafreguesiado3319
    @escoladejesusnafreguesiado3319 2 роки тому +1

    Very nice.
    But how about jump pagination, imagine i'm on page 3, and want to go to page 7, how do i implement that? there is a function to "jump x docs"?

    • @satyamgaba
      @satyamgaba Рік тому

      Any updates? I am wondering the same thing?

  • @everu1450
    @everu1450 5 років тому

    When are we getting that video on cloud functions that was promised in #5...?

  • @RikHaanen
    @RikHaanen 10 місяців тому

    Thanks, I really like your videos. Very clear. One question though: let’s say i page in 20 documents per page and i decide to get the top 60 documents at my 3rd page request. That means the first 40 documents are probably in my local cach alrery ?righ?. If that is the case, the server would only sent me the last missing 20 and not bill me for the 40 that i already have. Is thatvright? And would the system do that automatically our do i need to configure this local cach somehow? Thank, Rik

  • @nickjunes
    @nickjunes 3 роки тому

    Where doesn't seem to work with pagination. Is there a way to combine a where clause and pagination?

  • @sahilkarni1550
    @sahilkarni1550 Рік тому

    what if i use streams and streambuilder and list.view builder, do i still need to paginate ?

  • @juanalvarenga3393
    @juanalvarenga3393 4 роки тому

    How could I implement this idea in a chat according to what it mentions from the minute: 6:40, I am working in a chat and it is ready, but if I limit the number of messages in the first load and through a scroll I want to access data Previous, I miss the realtime, if someone has a very helpful example, thank you.

    • @mustafaalnoori5213
      @mustafaalnoori5213 3 роки тому

      Same idea but the query must be for ascending timestampe

  • @dearlordylord
    @dearlordylord 2 роки тому

    Where can I get an edible bear like in the video?

  • @sveinsoermo9883
    @sveinsoermo9883 5 років тому

    Would U recommend to combine aggregation with limit, or go with one or the other?

  • @narongchaijaroonpipatkul5294
    @narongchaijaroonpipatkul5294 4 роки тому

    I have a question.
    If my documents update index real time, What happen if I separate my collection to 2 collections ?
    First collection keep data and second keep only index but same key.
    Then I query first 500 keys from second collection and keep in array call "keys_array".
    Then I query data from first collection that same key in array 1 by 1 every 20 time when user scroll to the bottom of page.
    So I can manage pagination by myself and documents will not swap order in user's screen.
    And if this work, it can make numerical paginations.
    Because only index that's a number is more low cost than full data of document.

  • @JancoBH
    @JancoBH 5 років тому +1

    Nice video but what about a pagination for webs likes many blogs have with the next and previous pagination?

    • @Kinthalis
      @Kinthalis 5 років тому

      You can cache previous results in your store or what have you. But yeah, if there's a possibility that the user can request say page 20 right off the bat, like say in a forum board app, you'd probably have to work around this. Maybe adding an index to the document so that you can specifically query for document with index > 20 for example.

    • @skott1e
      @skott1e 5 років тому

      This would be expensive because the offset query for 20 records (limit: 20 offset: 40) that you would need for true oldschool pagination would cost 60 reads. Wait, let's say you have 5 pages with 10 records each. In your first query, you must retrieve all first and last records of each page. Then you can navigate with 'start before' and 'start after'. Hmm..

  • @rammalvarez2664
    @rammalvarez2664 5 років тому

    Really nice, super useful!

  • @ProfessionalTycoons
    @ProfessionalTycoons 4 роки тому

    super cool and useful!

  • @snj2102
    @snj2102 4 роки тому

    Great video!!! thanks

  • @pongstr
    @pongstr 5 років тому +1

    after watching this, im just not sure wether to paginate at all.. if you orderBy: date will it still return weird order?
    can you at least show some best practice code examples?

    • @madanhegde4153
      @madanhegde4153 5 років тому +1

      No! You can go ahead with this: 5:00

  • @Za-rk8gk
    @Za-rk8gk 4 роки тому +6

    This will be a big issue for most of the companies using Firestore, I was NOT expecting this.

    • @lazarkatanic4826
      @lazarkatanic4826 3 роки тому

      how?

    • @nivaldolemos5280
      @nivaldolemos5280 3 роки тому +3

      Most enterprise apps will need a numeric pagination somewhere, something that Firebase cannot offer. You can only travel to the previous or next page.

    • @akpokemon
      @akpokemon Рік тому

      @@nivaldolemos5280 I cannot believe this isn't a capability. Oh my god. What the h*ll... I might need to migrate to a completely new database platform...

  • @raismohamad2611
    @raismohamad2611 4 роки тому

    How do we know how many pages have using this method?

  • @jeancarloflorescarrasco412
    @jeancarloflorescarrasco412 4 роки тому

    Hi, I have a problem with limit, It always bring 20(for example), when only it is supposed to bring 10 elements. Yes ther another 10 are duplicateds

  • @27sosite73
    @27sosite73 2 роки тому +1

    nice

  • @whereismymind6696
    @whereismymind6696 5 років тому

    What about scrolling back up?

  • @lukecross5439
    @lukecross5439 4 роки тому

    Well, if the reads from database is scalling to the loaded documents+new documents instead of just new documents (already loaded documents not need load again) then is lower than the original recyclerView and RecyclerView FirebaseUI... this is very bad idea (you will lost realtime updates and your reads from database increases exponentially) .-.

  • @robertvos9044
    @robertvos9044 5 років тому

    Could RxFire stream handling paginate?

  • @matthewferguson8904
    @matthewferguson8904 5 років тому +6

    Wow sorry guys but this is terrible, we need proper paging...

  • @JeffLewis7
    @JeffLewis7 5 років тому +5

    1:40 Infinite Scroll with React Native and Cloud Firestore. How do I this?

  • @ecptavares
    @ecptavares 4 роки тому

    Hi! I have approximately 4.000 records on my firestore and I am paginating it by 20.But what if I am at the beginning and I want to search for an item that hasn't been loaded yet?How would I handle this situation?Thank you!

  • @ramunas_
    @ramunas_ 5 років тому

    How to know that it was the last document in the pagination fetch? Lets say I have 100 items and limiting by 20.

    • @ramunas_
      @ramunas_ 5 років тому

      @@ToddKerpelmanCorp Thanks!

  • @Rajukumar-nl2ok
    @Rajukumar-nl2ok 4 роки тому

    How can we achieve the pagination in PHP language.

  • @ben34256
    @ben34256 5 років тому

    Is there a security rule to limit the amount retrieved?

    • @amitk.512
      @amitk.512 5 років тому

      Yes we can limit it in security rules

    • @joereem
      @joereem 5 років тому

      An earlier video in this series explains how security rules cannot be used to limit the amount retrieved. If they are in place and a query is made that would be limited by a security rule, the query will fail.

  • @turskyi
    @turskyi 3 роки тому

    whereEqualTo cannot be used with orderBy!! this video has mistake at [7.57]

  • @zakariachahboun
    @zakariachahboun 5 років тому

    Thanks man!

  • @sture1985
    @sture1985 5 років тому

    #askfirebase Does the Firestore SDK support something like SELECT * from documents ORDER BY random() LIMIT 1?

    • @MyAsdfqwe
      @MyAsdfqwe 5 років тому

      it does, but by using bunch of functions provided in the api.

  • @jonasdo7805
    @jonasdo7805 4 роки тому +2

    why does everything feel like a one big hack with Cloud Firestore?

  • @sombriks
    @sombriks Рік тому

    hmm, use start instead offset. got it

  • @jonathangamble
    @jonathangamble 4 роки тому +2

    Bring 'offset' to the front end!!!

    • @ThatGuyAnonymous
      @ThatGuyAnonymous 4 роки тому +1

      offset works, except you, are charged for the docs you skipped. limit(5).offset(10) counts as 15 reads. once again the genius of firebase at work!

    • @ebonilha
      @ebonilha 4 роки тому +1

      offset is bad for security. Giving your users the power to read a million documents with a slim query is a leverage point for attacks. And this has nothing to do with Firebase. Limit/skip pagination for arbitrary queries must read all previous documents, and cursor-based ones don't. The only thing is that if you manage your own database this isn't a billing problem, but Firestore is billed per-read.

  • @sebasmite
    @sebasmite 3 роки тому

    Amazing

  • @shaikhsaiofali8432
    @shaikhsaiofali8432 5 років тому

    How can we implement this on stream builder?

    • @d-apps2699
      @d-apps2699 5 років тому

      I tried this with streambuilder and I don't recommend, If you just can load the documents, add in a list and show, It's better, that's how I doing on my app and it's working fine.

  • @alejandrorisco4201
    @alejandrorisco4201 4 роки тому

    Imagine that gummy bear made out of rum

  • @karthiksenthil1085
    @karthiksenthil1085 5 років тому

    how do phone otp authentication using react native and firebase please tell me

  • @luoidocsach
    @luoidocsach 5 років тому

    so you are charging on every single document read, that's so bad when I just want to have a total number of my documents and you charge me like I am doing 1000 read just because I have 1000 documents

    • @noumanhanif1948
      @noumanhanif1948 5 років тому

      keep a counter that you increment decrement on every document add/delete respectively. Then you will have the count in one read and you can do as many as you want

    • @akpokemon
      @akpokemon Рік тому

      @@noumanhanif1948 that doesn't account for any filters that your user applies in a search/filter bar

  • @JohnDoe-zc4mu
    @JohnDoe-zc4mu 5 років тому +8

    LMAO the gummy bear

  • @itssidhere
    @itssidhere 5 років тому

    How to get the last 50 docs ?

    • @ebonilha
      @ebonilha 4 роки тому +1

      Just reverse the sort. Switch ascending with descending or vice-versa

  • @ConstantinChirila
    @ConstantinChirila 4 роки тому +1

    This tutorial is misleading. There is no pagination. As after wasting half a day, there is still a very hard thing to do to just get the items with index 20 to 40 as they are in a document.

  • @xainard1114
    @xainard1114 5 років тому +2

    #askfirebase How to count without getting all document?

    • @Bigjunior987
      @Bigjunior987 5 років тому

      You can build a Cloud Function which cleverly counts the number of documents and saves it somewhere in the database.
      Keep in mind to deduplicate possible duplicate function executions.

    • @alexr.4409
      @alexr.4409 5 років тому

      not possible

  • @sherriecao3491
    @sherriecao3491 3 роки тому +1

    Brain: you are supposed to keep watching this tutorial
    Me: I WANT THIS GIANT GUMMY BEAR

  • @adiemar3974
    @adiemar3974 3 роки тому

    i just hope that firebase would find a solution for better pagination and dynamic queries, but as of now it's not one of the best for obvious reason.

  • @collinslagat3458
    @collinslagat3458 5 років тому

    Brilliant

  • @_sevelin
    @_sevelin 4 роки тому

    UA-cam team: What is the budget of UA-cam video?
    Google:
    UA-cam team: Lets buy a giant gummy bear.
    That's how it was done

  • @maxosall6972
    @maxosall6972 5 років тому

    Awesome

  • @deepseadiver971
    @deepseadiver971 3 роки тому

    A downloadable Xcode sample project would have been nice.. You spoke on how to use it BUT didn't show the specifics concerning snapshot/listener code implementation... Disappointed.

  • @lucaban
    @lucaban 4 роки тому

    What is `whereField()` ? :D why not just `where()` ?

  • @Pizzaguy2
    @Pizzaguy2 3 роки тому

    I still dont know how to do it , I only learned how not to do it

  • @かやひこ
    @かやひこ 5 років тому

    i want that gummy bear

  • @rickloyd8208
    @rickloyd8208 5 років тому

    Awesome but I would prefer either limit star, end or after row_id. That way I can see from code what's going on and save on execution of extra code. May be I am too old fashioned :)
    Awesome, I had no clue that offset would charge me for all reads I am not actually getting. Another warning that developer should read documentation to get the best results for lowest price :)

  • @Klazyo
    @Klazyo 4 роки тому +1

    I don't have Money

  • @benton202
    @benton202 4 роки тому

    this is the most confusing function of firestore .....

  • @zorloth
    @zorloth 5 років тому

    wow, startAfter instead of offset. Bet loads of people are using offset and wasting $$.

  • @diogogaio
    @diogogaio 8 місяців тому +1

    lots of limitations...., poor methods, video is old....

  • @lukecross5439
    @lukecross5439 4 роки тому

    FirebaseUI Pagination not can capturate the Snapshot Document

  • @jorgemoraleslopez5575
    @jorgemoraleslopez5575 5 років тому

    This video has opened the way for me, I am doing geospatial queries with geofirex, github.com/codediodeio/geofirex, but it is not possible to page and at the moment it does not have a limit method, I could see in its explanation that the way, although it is expensive would be to increase the limit in each query ... This library does have the ability to limit queries https: //github.com/geofirestore/geofirestore-js ... There is a better alternative for geospatial queries for javascript?

  • @John-doe793
    @John-doe793 4 роки тому

    broo I spent a lot of time "paginating" as documentation says then I realised that I can use 'offset'... dammit

    • @sudomakes
      @sudomakes 4 роки тому +2

      Maybe you didn't listen till the end... You get billed even for the documents you are supposed to offset by, which defeats the purpose

    • @varunmanjunath9123
      @varunmanjunath9123 4 роки тому

      @@sudomakes ikr, hope that guy read your comment, or his firebase app will give him A BIG CHONKY bill of 500$ one day... xD

  • @tntg5
    @tntg5 2 роки тому +1

    Please add getLength() method to collections. Otherwise, pagination feels like walking down stairs blindfolded