Skip to content

Commit

Permalink
PHPLIB-1513: Remove the mapReduce helper
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Sep 26, 2024
1 parent f95d1cb commit 4edfa16
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 1,069 deletions.
5 changes: 4 additions & 1 deletion UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ UPGRADE FROM 1.x to 2.0
`MongoDB\Model\IndexInfo` class.
* The `maxScan`, `modifiers`, `oplogReplay`, and `snapshot` options for `find`
and `findOne` operations have been removed.
* The `MongoDB\Collection::mapReduce` method has been removed. Use aggregation
pipeline instead.
* The following classes and interfaces have been removed without replacement:
* `MongoDB\Operation\Executable`
* `MongoDB\MapReduceResult`
* `MongoDB\Model\CollectionInfoCommandIterator`
* `MongoDB\Model\CollectionInfoIterator`
* `MongoDB\Model\DatabaseInfoIterator`
* `MongoDB\Model\DatabaseInfoLegacyIterator`
* `MongoDB\Model\IndexInfoIterator`
* `MongoDB\Model\IndexInfoIteratorIterator`
* `MongoDB\Operation\Executable`

GridFS
------
Expand Down
17 changes: 0 additions & 17 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -744,23 +744,6 @@
<code><![CDATA[$options['session']]]></code>
</MixedAssignment>
</file>
<file src="src/Operation/MapReduce.php">
<MixedArgument>
<code><![CDATA[$result->result->collection]]></code>
<code><![CDATA[$result->result->db]]></code>
<code><![CDATA[$this->options['typeMap']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$cmd[$option]]]></code>
<code><![CDATA[$options['readConcern']]]></code>
<code><![CDATA[$options['readPreference']]]></code>
<code><![CDATA[$options['session']]]></code>
<code><![CDATA[$options['writeConcern']]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[isInTransaction]]></code>
</MixedMethodCall>
</file>
<file src="src/Operation/ModifyCollection.php">
<MixedArgument>
<code><![CDATA[$this->options['typeMap']]]></code>
Expand Down
48 changes: 0 additions & 48 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Countable;
use Iterator;
use MongoDB\BSON\Document;
use MongoDB\BSON\JavascriptInterface;
use MongoDB\BSON\PackedArray;
use MongoDB\Builder\BuilderEncoder;
use MongoDB\Builder\Pipeline;
Expand Down Expand Up @@ -63,7 +62,6 @@
use MongoDB\Operation\InsertOne;
use MongoDB\Operation\ListIndexes;
use MongoDB\Operation\ListSearchIndexes;
use MongoDB\Operation\MapReduce;
use MongoDB\Operation\RenameCollection;
use MongoDB\Operation\ReplaceOne;
use MongoDB\Operation\UpdateMany;
Expand All @@ -77,11 +75,7 @@
use function array_key_exists;
use function current;
use function is_array;
use function sprintf;
use function strlen;
use function trigger_error;

use const E_USER_DEPRECATED;

class Collection
{
Expand Down Expand Up @@ -908,48 +902,6 @@ public function listSearchIndexes(array $options = []): Iterator
return $operation->execute($server);
}

/**
* Executes a map-reduce aggregation on the collection.
*
* @see MapReduce::__construct() for supported options
* @see https://mongodb.com/docs/manual/reference/command/mapReduce/
* @param JavascriptInterface $map Map function
* @param JavascriptInterface $reduce Reduce function
* @param string|array|object $out Output specification
* @param array $options Command options
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
* @throws UnexpectedValueException if the command response was malformed
*/
public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, string|array|object $out, array $options = []): MapReduceResult
{
@trigger_error(sprintf('The %s method is deprecated and will be removed in a version 2.0.', __METHOD__), E_USER_DEPRECATED);

$hasOutputCollection = ! is_mapreduce_output_inline($out);

// Check if the out option is inline because we will want to coerce a primary read preference if not
if ($hasOutputCollection) {
$options['readPreference'] = new ReadPreference(ReadPreference::PRIMARY);
} else {
$options = $this->inheritReadPreference($options);
}

/* A "majority" read concern is not compatible with inline output, so
* avoid providing the Collection's read concern if it would conflict.
*/
if (! $hasOutputCollection || $this->readConcern->getLevel() !== ReadConcern::MAJORITY) {
$options = $this->inheritReadConcern($options);
}

$options = $this->inheritWriteOptions($options);
$options = $this->inheritTypeMap($options);

$operation = new MapReduce($this->databaseName, $this->collectionName, $map, $reduce, $out, $options);

return $operation->execute(select_server_for_write($this->manager, $options));
}

/**
* Renames the collection.
*
Expand Down
103 changes: 0 additions & 103 deletions src/MapReduceResult.php

This file was deleted.

Loading

0 comments on commit 4edfa16

Please sign in to comment.