Hey, did everyone share?
And in this video, we're going to work with the where clause of the pagination or the fine method.
Now, usually I never, ever create a method or a separate class or an instance for the pagination because
it is really too simple to work on with that.
All you got to do is use two method that is just limit and skip.
Limit is how much values you want to show in a page itself or add the one request and skip is how many
values you want to skip it.
So this is all what it got.
So here it is, the documentation which says aggregate prototype limit, maximum number of records to
pass on to the next stage.
And then we have got another one which is kid that how many records you want to skip.
So for example, you want to show, let's just say five products on the page one.
So obviously this time your limit is just five and your page is number one on the page.
Number two, you want to skip the first initial five product and want to move to the next five products.
That's really simple.
So we don't use any kind of methods for that.
But since we are writing this entirety of the WHERE clause, let's go ahead and work on with that.
So in this case, just below the search, wherever you like.
So let's just go here into this one.
Let's create a simple method.
Let's call this one s page.
Now, page one absolute requirement is it needs to give me that.
How many page you want to show per page.
It's not going to magically know.
No.
That so we're going to go ahead and say result per page.
So you have to give me that.
Now I'm going to assume that let the current pages because you have to actually kind of assume that
what is going to be the current page?
Now current page is going to be one.
So that is my assumption here.
Again, I forgot a simple parenthesis.
There we go.
And I need to move this in.
There we go.
So I assumed that my current page is one.
But there is a chance that inside this big query you might have passed me on a page number that is page
equals to two.
So I have to update this current page based on that if something is coming in.
Otherwise, by default, all visitors current page is one.
So let's just go ahead and say that if let's just access this one.
So this dot big Q So inside this big query, if there is a dot page variable available, then only I'm
going to go ahead and say, hey, let's just go ahead and update this current page to equal to whatever
the value is.
So this dot big query, dot page, so it will obviously key value properties like this.
So I'm accessing the key of page, it will give me a value and that will be added to the current page.
That is nice if that value exists.
Now the thing is really simple that I have to simply go ahead and say that, hey, this dot base and
inside this dot base, we're going to go ahead and add this one.
So again, previously we were saying this dot find, but this time we have to use two things.
This dot limit, it will get some value as well, not limité.
That looks like French.
Again, we're going to go ahead and add a skip value here as well.
Okay.
So these two values we need to work on with that.
So how much is the limit?
Limit is pretty simple.
I can just go ahead and grab this result per page, so I'm going to go ahead and add this one.
So there we go.
Now, the important part is how can I find that how many values I have to skip?
Because on the page one, I have to skip zero values on the page too.
Let's just say we are going for five page per result.
I have to skip five values.
Then on the third page I have to skip the ten values.
So this is a little bit of a complex work, not really that much complex.
There is a well-known formula for that.
So let's go ahead and work on with that.
So we're going to go ahead and say, hey, how many values I have to skip?
Skip Well, that is actually calculated and that is why we actually need this result per page.
So the formula is really simple result per page is going to go ahead and multiply by whatever the current
page value is, and we have to subtract one from it because on the first page we actually shows all
the values.
So again, you can go ahead and try to test these values.
So in the result per page, let's just say we have five values.
So five, let's just go ahead and do some of the mathematics because I know some of you will become
confused.
So result per page is five and we are going to go ahead and multiply it by.
Let's just say we are on to the first page.
So one minus one is going to be zero.
So you'll be showing zero values on that.
But the current page is actually going.
So we are going to basically skip zero values.
So that's what this basically means.
So in this case.
But what about if we are on to the second page to two minus one, that means we are on the first page.
So how many values we go to skip?
One five.
You get the idea so you can do more mathematics of that.
I wouldn't be doing much more than this.
This is a very well known formula for all the pagination and you can go ahead and add a skip well onto
that.
It is so much well known that a lot of people actually kind of buy hard this one and we need to update
the query as well.
So whatever the.
Where he actually came in.
Now, this is the fresh, fresh base that we have got up here.
So let's go ahead and do this one again.
Product find is going to be as a test, whatever the value you have injected in the search and everything.
And on top of that, further down the road, we are actually adding limit and skip on to this one.
So let's go ahead and add this one.
So this one is going to be this dot base is going to be like this one.
So further down the road, a dot find and then we are adding dot limit and dot skip whatever we are
having.
Okay, further down the road, let's go ahead and simply say return this and that's it.
We are returning the entire reference.
So again, really simple.
And again, you will be using this line quite a lot.
So in case you want to go ahead and add this one on to your notes or somewhere, go ahead and do that.
That's a simple page for you.
Let's go ahead and catch up in the next video.