batch() public method (available since version 2.1)
Starts a batch query. A batch query supports fetching data in batches, which can keep the memory usage under a limit. This method will return a yii\mongodb\BatchQueryResult object which implements the Iterator interface and can be traversed to retrieve the data in batches. For example, $query = (new Query)->from('user');
foreach ($query->batch() as $rows) {
// $rows is an array of 10 or fewer rows from user collection
}
public