Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Operation/MapReduce.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class MapReduce implements Executable
* This is not supported for server versions < 3.4 and will result in an
* exception at execution time if used.
*
* * finalize (MongoDB\BSON\Javascript): Follows the reduce method and
* modifies the output.
* * finalize (MongoDB\BSON\JavascriptInterface): Follows the reduce method
* and modifies the output.
*
* * jsMode (boolean): Specifies whether to convert intermediate data into
* BSON format between the execution of the map and reduce functions.
Expand Down Expand Up @@ -155,7 +155,7 @@ public function __construct($databaseName, $collectionName, JavascriptInterface
throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object');
}

if (isset($options['finalize']) && ! $options['finalize'] instanceof Javascript) {
if (isset($options['finalize']) && ! $options['finalize'] instanceof JavascriptInterface) {
throw InvalidArgumentException::invalidType('"finalize" option', $options['finalize'], 'MongoDB\Driver\Javascript');
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Operation/MapReduceFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ function(stdClass $command) {
$operation->execute($this->getPrimaryServer());
}

public function testFinalize()
{
$this->createFixtures(3);

$map = new Javascript('function() { emit(this.x, this.y); }');
$reduce = new Javascript('function(key, values) { return Array.sum(values); }');
$out = ['inline' => 1];
$finalize = new Javascript('function(key, reducedValue) { return reducedValue; }');

$operation = new MapReduce($this->getDatabaseName(), $this->getCollectionName(), $map, $reduce, $out, ['finalize' => $finalize]);
$result = $operation->execute($this->getPrimaryServer());

$this->assertNotNull($result);
}

public function testResult()
{
$this->createFixtures(3);
Expand Down