AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。

MongoDB\MapReduceResult::getIterator()

MongoDB\MapReduceResult::getIterator()

map-reduce操作の結果を反復処理するために使用できるTraversableを返します。

function getIterator(): Traversable

走査可能、map-reduce操作の結果を反復処理するために使用できます。

この例では、map-reduce 操作の結果を反復処理します。

<?php $collection = (new MongoDB\Client)->test->zips; $map = new MongoDB\BSON\Javascript('function() { emit(this.state, this.pop); }');$reduce = new MongoDB\BSON\Javascript('function(key, values) { return Array.sum(values) }');$out = ['inline' => 1]; $result = $collection->mapReduce($map, $reduce, $out); foreach ($result as $population) { var_dump($population);};

出力は次のようになります。

object(stdClass)#2293 (2) { ["_id"]=> string(2) "AK" ["value"]=> float(544698)}object(stdClass)#2300 (2) { ["_id"]=> string(2) "AL" ["value"]=> float(4040587)}object(stdClass)#2293 (2) { ["_id"]=> string(2) "AR" ["value"]=> float(2350725)}object(stdClass)#2300 (2) { ["_id"]=> string(2) "AZ" ["value"]=> float(3665228)}