Feature: Add forAll for cursor queries
See original GitHub issueDo you want to request a feature or report a bug? Feature
Feature Description
For cursor queries (that return the data in batches) currently there is a method forEach
which is used to loop over each document returned from the query not each batch. it would be nice to loop over each batch so you can perform a bulk action on each batch.
Use Case
You want to send an email to all users currently in your system obviously you will fetch the whole user collection in batches. But it’s not very efficient to send each user an email one at a time that wouldn’t be very cost effective plus any mail service has a limit on the max number of bulk emails that could be sent (1000 for example). So the ideal situation would be to fetch the users in batches of 1000 and for each batch perform a bulk action of sending an email to all those users.
I can make the PR myself but I will wait for the issue approval
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
I think a
batchSize
option toeachAsync()
would work if you’re willing to put in a PR 👍@vkarpov15 Done I don’t know exactly how you manage features but the feature branch was based on branch 6.0 and the PR is on branch 6.0 also I didn’t want to come near the master branch as I’m assuming this is the branch used for the latest mongoose version