Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to apply skip and limit parameters on the cursor count operation #399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jgerlier
Copy link

@jgerlier jgerlier commented Mar 9, 2023

I figured out that even when backed by an index, the count operation will still have to scan every matched index key when used with a query. This can lead to performance issues when counting on large collection (for pagination for example).

To mitigate these issues the MongoDB shell allow to pass a applySkipLimit boolean parameter to the cursor.count() method to apply the skip and limit parameters of the cursor to the count operation. This way the count will stop when reaching the limit (which is often fine for pagination, as we rarely need to scroll until the last pages).

The goal of this PR is to add this parameter to the count method of the MongoCursor class in order to reflect the contract of the MongoDB shell method.

cc @Dayde

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.

1 participant