Skip to content

Conversation

@GromNaN
Copy link
Member

@GromNaN GromNaN commented Nov 8, 2023

Fix PHPORM-106

Pagination needs 2 queries:

  1. Get the total count
  2. Select the items for the specified page using offset/limit.

For 1, Eloquent wraps the raw SQL into an other SQL queries. For MongoDB, we use an aggregation pipeline for groupBy queries. Getting the total count is as simple as adding a $count stage to the pipeline.
For 2, nothing to do, the pagination leverages the query builder offset/limit methods that already works with aggregation pipeline.

I have to explicitly restrict usage of the pagination on distinct queries, as the Collection::distinct() method doesn't support counting.

@GromNaN GromNaN merged commit 1eda4de into mongodb:4.1 Nov 9, 2023
@GromNaN GromNaN deleted the PHPORM-106 branch November 9, 2023 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants