Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Default to last page when trying to query a page greater than total pages. #167

Open
gabrielgasp opened this issue Apr 19, 2022 · 1 comment
Assignees
Labels
workingon Working On

Comments

@gabrielgasp
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I wouldn't call it a problem but when we try to query a page greater than the total number of pages available the lib try to query said page and we get an empty array.

Describe the solution you'd like
I think it would be nice we the lib defaults to the last available page when this happens (or at least gives the option to).

Describe alternatives you've considered
Not sure how the implementation would be in the lib's code but I circumvented this situation in my code doing a simple check as follows.

// Check if the requested page is greater than the total number of pages for the provided limit based on our collection's document count.
if (pageNumber * limitNumber > documentCountInCollection) {
// If the requested page is indeed greater, set the requested page to the last possible page.
  pageNumber = Math.ceil(documentCountInCollection / limitNumber)
}

Additional context
This is something we can easily deal with in our code and I understand it's not a priority in any way but I think this behavior would be well received by the users. I'll try to implement this myself and open a pull request when I get some free time but thought would be nice to leave the issue here in case someone decides to try it before me.

@aravindnc aravindnc self-assigned this Jun 8, 2022
@aravindnc
Copy link
Owner

@GabrielGaspar447 Thanks for pointing this out. I will add a fix soon.

@aravindnc aravindnc added the workingon Working On label Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
workingon Working On
Projects
None yet
Development

No branches or pull requests

2 participants