Skip to content

Commit

Permalink
Fixed incorrect continuation token when searching with sort
Browse files Browse the repository at this point in the history
The continuation token was generated based on _mongo.partitionKey.
This is correct when _mongo.partitionKey is the only sort field.  When
there are other sort fields in the query, the sequence of records are
influenced by those fields. Continuation token based on only
_mongo.partitionKey value does not produce the correct results for next
pages.

There is a npm package on "cursor based pagination":
https://www.npmjs.com/package/mongo-cursor-pagination
The library supports one "paginatedField".  The ClearlyDefined api
supports sort resulting in multiple sort fields. For example: sort on
namespace sorts on three fields: ['coordinates.namespace',
'coordinates.name', 'coordinates.revision'].  So the library is not
sufficient for CD's need.

To generate the correct next page, the continuation token needs to
record all the values for sort fields. As an extension of existing logic,
_mongo.partitionKey will always be included to the sort fields as a tie
breaker. Also added logic to generate pagination query based on
multiple sort values.
  • Loading branch information
qtomlinson committed Jan 31, 2023
1 parent 8f06877 commit 4994741
Show file tree
Hide file tree
Showing 6 changed files with 3,029 additions and 33 deletions.
Loading

0 comments on commit 4994741

Please sign in to comment.