asFlow

Streams the results into a Flow.

The flow is lazy: new elements are streamed in when the consumer requests them.

MongoDB cursors are batched: a batch is queried, processed, then another batch is requested, etc. The batch size can be configured in the operation creating this iterable.

If you intend to query a large number of batches and perform complex operations on them, we recommend using buffer with a low capacity, to reduce latency between two batches.

See also

Execute an action for each result.

Store all results in a List.

Store all results in a Set.