Skip to content

Commit 08865f0

Browse files
committed
PHPLIB-242: Refactor MapReduce to use field path syntax in type map
1 parent 7406234 commit 08865f0

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Operation/MapReduce.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use MongoDB\Exception\InvalidArgumentException;
2929
use MongoDB\Exception\UnexpectedValueException;
3030
use MongoDB\Exception\UnsupportedException;
31-
use MongoDB\Model\TypeMapArrayIterator;
3231
use MongoDB\MapReduceResult;
3332
use ArrayIterator;
3433
use stdClass;
@@ -267,6 +266,10 @@ public function execute(Server $server)
267266
? $server->executeReadWriteCommand($this->databaseName, $command, $options)
268267
: $server->executeReadCommand($this->databaseName, $command, $options);
269268

269+
if (isset($this->options['typeMap']) && ! $hasOutputCollection) {
270+
$cursor->setTypeMap(\MongoDB\create_field_path_type_map($this->options['typeMap'], 'results.$'));
271+
}
272+
270273
$result = current($cursor->toArray());
271274

272275
$getIterator = $this->createGetIteratorCallable($result, $server);
@@ -326,10 +329,6 @@ private function createGetIteratorCallable(stdClass $result, Server $server)
326329
$results = $result->results;
327330

328331
return function() use ($results) {
329-
if (isset($this->options['typeMap'])) {
330-
return new TypeMapArrayIterator($results, $this->options['typeMap']);
331-
}
332-
333332
return new ArrayIterator($results);
334333
};
335334
}

0 commit comments

Comments
 (0)