Skip to content

Add pagination with cursor #7637

Open
Open
@mtrezza

Description

@mtrezza

New Feature / Enhancement Checklist

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 #7440 (comment). 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 parse-community/parse-dashboard#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bounty:$250Bounty applies for fixing this issue (Parse Bounty Program)type:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions