I have updated mongo and now in the log the following error appears: Use of the aggregate command without the cursor option is deprecated
Mo
You have to use aggregateCursor
which returns the cursor row instead of results
only.
Something like
The first batch is by default set at 101 results.
$cur = $this->db->{$collection}->aggregateCursor($pipeline);
Set the batchsize ( the second parameter from your question ) on aggregate cursor of 50 for subsequent batches. If you don't use below option the default will fetch around 4 MB.
$cur->batchSize( 50 );
You can now iterate and read results to get all documents.
The server will fetch initial(first) batch of 101 documents on first loop iteration followed by subsequent batch at 102 iteration and at intervals of 50 on rest of batches until you exhaust the cursor.
foreach ( $cur as $result )
{
echo $result['_id'], "\n";
}
To control batch size for first batch, you can specify batchSize
as cursor option but generally it is not needed.
$cur = $this->db->{$collection}->aggregateCursor($pipeline, 'cursor' => [ 'batchSize' => 1 ]);
Reference: https://derickrethans.nl/aggregation-cursor.html