parse-community / parse-community/parse-server
Add pagination with cursor
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 21.4k
- Forks
- 4.8k
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 11
Description
New Feature / Enhancement Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
Current Limitation
Query results pagination can currently only be achieved by using limit and skip. A MongoDB query however also returns a cursor that can be used to paginate through query results.
Feature / Enhancement Description
- Add the query result cursor to response of a query as meta data.
- Add a methods to interact with the cursor.
For example:
let q = new Parse.Query();
q.equalTo(...);
const response = await q.find();
const page1 = response.results;
const cursor = response.cursor;
q = Parse.Query.fromCursor(cursor);
q.skip(100);
q.limit(100);
const page2 = await q.find();
Or alternatively introduce an entirely new command set for cursor operations, for example:
c = Parse.QueryCursor(cursor);
c.moveToPosition(100);
const page2 = await c.return(100);
Returning meta data together with the response is related to a pending change of the response object for a sustainable modification of the response JSON structure, see https://github.com/parse-community/parse-server/pull/7440#discussion_r678916891. Returning a cursor together with results is one use case that justifies the change of the query response from a ParseObject array to this more versatile form:
{
results: [...],
meta: {
cursor: ...,
explain: ...
}
}
Example Use Case
See the current challenge of pagination in Parse Dashboard in https://github.com/parse-community/parse-dashboard/issues/1551.
Alternatives / Workarounds
Paginate using limit and skip with the major downside of each pagination request issuing a new query instead of using the existing cached query results on the database side. The other challenge is that each new query is done over a potentially changing data set, so the limit / skip parameters become inaccurate.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing limit/skip query response flow and the pending response-object discussion in pull request 7440. Compare the proposed cursor metadata and cursor interaction alternatives with the Parse Dashboard pagination use case in issue 1551. Done means an agreed API design that supports stable cursor pagination without relying on changing limit/skip results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb, node.js
- Domain
- api, backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100