Beispiel #1
0
 /**
  * Starts a batch query and retrieves data row by row.
  * This method is similar to [[batch()]] except that in each iteration of the result,
  * only one row of data is returned. For example,
  *
  * ```php
  * $query = (new Query)->from('user');
  * foreach ($query->each() as $row) {
  * }
  * ```
  *
  * @param int $batchSize the number of records to be fetched in each batch.
  * @param Connection $db the MongoDB connection. If not set, the "mongodb" application component will be used.
  * @return BatchQueryResult the batch query result. It implements the `Iterator` interface
  * and can be traversed to retrieve the data in batches.
  * @since 2.1
  */
 public function each($batchSize = 100, $db = null)
 {
     return Yii::createObject(['class' => BatchQueryResult::className(), 'query' => $this, 'batchSize' => $batchSize, 'db' => $db, 'each' => true]);
 }