jongo
jongo copied to clipboard
Allow to apply skip and limit parameters on the cursor count operation
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