Skip to content

Commit 7406234

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

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Operation/Aggregate.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use MongoDB\Exception\InvalidArgumentException;
2828
use MongoDB\Exception\UnexpectedValueException;
2929
use MongoDB\Exception\UnsupportedException;
30-
use MongoDB\Model\TypeMapArrayIterator;
3130
use ArrayIterator;
3231
use stdClass;
3332
use Traversable;
@@ -280,16 +279,16 @@ public function execute(Server $server)
280279
return $cursor;
281280
}
282281

282+
if (isset($this->options['typeMap'])) {
283+
$cursor->setTypeMap(\MongoDB\create_field_path_type_map($this->options['typeMap'], 'result.$'));
284+
}
285+
283286
$result = current($cursor->toArray());
284287

285288
if ( ! isset($result->result) || ! is_array($result->result)) {
286289
throw new UnexpectedValueException('aggregate command did not return a "result" array');
287290
}
288291

289-
if (isset($this->options['typeMap'])) {
290-
return new TypeMapArrayIterator($result->result, $this->options['typeMap']);
291-
}
292-
293292
return new ArrayIterator($result->result);
294293
}
295294

0 commit comments

Comments
 (0)