forEach
inline suspend fun <Document : Any> MongoAggregationPipeline<Document>.forEach(noinline action: suspend (Document) -> Unit)(source)
Executes action for each document returned by this query.
This method streams all returned documents into the action function. The entire response set is not loaded at once into memory.
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 the operation contains a sort without an index, MongoDB will load all results into memory. The driver will still stream the results.