Fireship · @fireship

Firestore Pagination - It Just Got Easier

Uploaded November 26, 2019 · Length 6:41

Firestore Pagination - It Just Got Easier

Summary

Implementing pagination in Firestore using the limit to last method, making it easier to navigate through large collections of data.

  • firestore pagination
  • limit to last method
  • firebase pagination
  • spelt fire
  • pagination in firestore

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    fire-based recently released a new query

  2. 0:01

    method called limit to last it's

  3. 0:03

    available in version 7.3 or greater of

  4. 0:05

    the JavaScript SDK and in today's video

  5. 0:07

    I'll show you exactly why it's so useful

  6. 0:09

    by implementing a pagination feature

  7. 0:11

    with firestore if you're new here like

  8. 0:13

    and subscribe and check out a discount

  9. 0:15

    code in the description below for Black

  10. 0:17

    Friday it's active now so feel free to

  11. 0:19

    use that if you want to become any Pro

  12. 0:21

    member you'll get access to the

  13. 0:22

    firestore data modeling course along

  14. 0:24

    with a bunch of other advanced firebase

  15. 0:25

    content for today's video let's start by

  16. 0:28

    talking about the problem that we're

  17. 0:29

    trying to solve you may have a large

  18. 0:30

    collection of data that you want to show

  19. 0:32

    to the user in batches or in other words

  20. 0:35

    you want to split your data into a

  21. 0:36

    discrete set of pages and allow the user

  22. 0:39

    to click through those pages if you've

  23. 0:41

    ever tried to implement pagination and

  24. 0:42

    firestore in the past you might know

  25. 0:44

    that it's pretty easy to go in a forward

  26. 0:45

    direction but going backwards to a

  27. 0:47

    previous page was not so easy

  28. 0:49

    you'd have to follow these four steps

  29. 0:50

    which just isn't very intuitive or

  30. 0:52

    something that you would think would be

  31. 0:54

    relatively easy well I have some good

  32. 0:55

    news for you the limit to last method

  33. 0:57

    makes this process much easier it's

  34. 0:59

    similar to the existing limit method but

  35. 1:01

    instead of limiting to the first end

  36. 1:03

    results it limits to the last end

  37. 1:05

    results over the next few minutes we'll

  38. 1:07

    look at the implementation details from

  39. 1:08

    scratch but I first want to show you the

  40. 1:10

    query functions that make this possible

  41. 1:12

    and make sure to stay tuned until the

  42. 1:14

    end of the video because I'm going to

  43. 1:16

    discuss some of the limitations of

  44. 1:17

    pagination and firestore in general for

  45. 1:20

    this demo we'll be using spelt along

  46. 1:22

    with a new library that I wrote called

  47. 1:23

    spelt fire the pagination queries and

  48. 1:26

    principles applied to all frameworks

  49. 1:28

    across all programming languages but as

  50. 1:30

    you'll see in a few minutes spelt fire

  51. 1:32

    provides some special magic to make

  52. 1:33

    pagination even easier but I know not

  53. 1:36

    everybody's using spelt yet so let's

  54. 1:37

    start by just focusing on the queries

  55. 1:39

    that we need to make for pagination to

  56. 1:41

    work the first thing you'll need to do

  57. 1:43

    is make an initial query on your

  58. 1:44

    collection it needs to be ordered by a

  59. 1:46

    certain field and should be limited to a

  60. 1:48

    specific page size so that's pretty

  61. 1:51

    straightforward but when you want to

  62. 1:52

    navigate to the next page you need to

  63. 1:54

    offset by the last result in that first

  64. 1:56

    page this is pretty straightforward and

  65. 1:59

    uses query methods that have been