Fireship · @fireship
Firestore Pagination - It Just Got Easier
Uploaded November 26, 2019 · Length 6:41
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.
- 0:00
fire-based recently released a new query
- 0:01
method called limit to last it's
- 0:03
available in version 7.3 or greater of
- 0:05
the JavaScript SDK and in today's video
- 0:07
I'll show you exactly why it's so useful
- 0:09
by implementing a pagination feature
- 0:11
with firestore if you're new here like
- 0:13
and subscribe and check out a discount
- 0:15
code in the description below for Black
- 0:17
Friday it's active now so feel free to
- 0:19
use that if you want to become any Pro
- 0:21
member you'll get access to the
- 0:22
firestore data modeling course along
- 0:24
with a bunch of other advanced firebase
- 0:25
content for today's video let's start by
- 0:28
talking about the problem that we're
- 0:29
trying to solve you may have a large
- 0:30
collection of data that you want to show
- 0:32
to the user in batches or in other words
- 0:35
you want to split your data into a
- 0:36
discrete set of pages and allow the user
- 0:39
to click through those pages if you've
- 0:41
ever tried to implement pagination and
- 0:42
firestore in the past you might know
- 0:44
that it's pretty easy to go in a forward
- 0:45
direction but going backwards to a
- 0:47
previous page was not so easy
- 0:49
you'd have to follow these four steps
- 0:50
which just isn't very intuitive or
- 0:52
something that you would think would be
- 0:54
relatively easy well I have some good
- 0:55
news for you the limit to last method
- 0:57
makes this process much easier it's
- 0:59
similar to the existing limit method but
- 1:01
instead of limiting to the first end
- 1:03
results it limits to the last end
- 1:05
results over the next few minutes we'll
- 1:07
look at the implementation details from
- 1:08
scratch but I first want to show you the
- 1:10
query functions that make this possible
- 1:12
and make sure to stay tuned until the
- 1:14
end of the video because I'm going to
- 1:16
discuss some of the limitations of
- 1:17
pagination and firestore in general for
- 1:20
this demo we'll be using spelt along
- 1:22
with a new library that I wrote called
- 1:23
spelt fire the pagination queries and
- 1:26
principles applied to all frameworks
- 1:28
across all programming languages but as
- 1:30
you'll see in a few minutes spelt fire
- 1:32
provides some special magic to make
- 1:33
pagination even easier but I know not
- 1:36
everybody's using spelt yet so let's
- 1:37
start by just focusing on the queries
- 1:39
that we need to make for pagination to
- 1:41
work the first thing you'll need to do
- 1:43
is make an initial query on your
- 1:44
collection it needs to be ordered by a
- 1:46
certain field and should be limited to a
- 1:48
specific page size so that's pretty
- 1:51
straightforward but when you want to
- 1:52
navigate to the next page you need to
- 1:54
offset by the last result in that first
- 1:56
page this is pretty straightforward and
- 1:59
uses query methods that have been


