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

Pagination #46

Open
alexborisov opened this issue Aug 5, 2016 · 3 comments
Open

Pagination #46

alexborisov opened this issue Aug 5, 2016 · 3 comments

Comments

@alexborisov
Copy link

alexborisov commented Aug 5, 2016

Hey,

Any thoughts on how to implement a custom page/limit filter? Near as I can tell this itsn't handled in a normal query which gets built, but are additional operators find().limit().skip()

@Starefossen
Copy link
Contributor

Yes, this is something I have thought of but I have not concluded on what the best API interface should look like. Any suggestions?

@alexborisov
Copy link
Author

alexborisov commented Aug 5, 2016

Commonly this is done via a ?limit&page. On a side note it's actually not super efficient to use skip because this is done on a cursor so the data is first fetched in it's entirety and then paged. Mongo suggests using ranged queries using either a date field or _id (which is sorted). So you would then ask for the next 10 records starting form date/id X.

Personally I think this can all get a little messy. Perhaps a better approach would be to consider doing all of this via the aggregation pipeline. The benefit of this is that your query object is an array of aggregation queries so you can build this up with the middleware and pass a single query object to mongo (for instance how would you easily handle count, skip, limit or any other cursor operation?).

You could even make this an option (so the output of this middleware will either be a simple query or a pipeline)

@mhirsch
Copy link

mhirsch commented Dec 21, 2016

I'd love to see something like this as well. Thanks for a great project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants