Pagination kills performance with big MongoDB document collections
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.
We have the same problem. May be there are some workarounds?