core icon indicating copy to clipboard operation
core copied to clipboard

Pagination kills performance with big MongoDB document collections

Open rimas-kudelis opened this issue 5 years ago • 1 comments

When a MongoDB collection holding a big number of documents is paginated, even if no filters are applied, the performance of this action is very low. For example, a request to get a page in a collection of ~2.5M documents takes me somewhere between 8 and 9 seconds to finish. I'm thinking that perhaps it would be a good idea to:

A) allow disabling counting altogether, at least on the API Platform side. This should be configurable. Looking at #2473, it seems that something similar is already implemented for ORM, so perhaps same logic could be reused with ODM.

B) issuing a separate query to count documents. This would be helpful at least in those cases where $count could then use an index, because apparently, indices are not used in $facet pipelines.

rimas-kudelis avatar Oct 10 '20 11:10 rimas-kudelis

We have the same problem. May be there are some workarounds?

p-golovin avatar Mar 23 '22 11:03 p-golovin