Skip to content

Commit 02de19c

Browse files
committed
PHPLIB-1513: Remove the mapReduce helper
1 parent e9331d2 commit 02de19c

12 files changed

+9
-1069
lines changed

UPGRADE-2.0.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ UPGRADE FROM 1.x to 2.0
1010
`MongoDB\Model\IndexInfo` class.
1111
* The `maxScan`, `modifiers`, `oplogReplay`, and `snapshot` options for `find`
1212
and `findOne` operations have been removed.
13+
* The `MongoDB\Collection::mapReduce` method has been removed. Use aggregation
14+
pipeline instead.
1315
* The following classes and interfaces have been removed without replacement:
14-
* `MongoDB\Operation\Executable`
16+
* `MongoDB\MapReduceResult`
1517
* `MongoDB\Model\CollectionInfoCommandIterator`
1618
* `MongoDB\Model\CollectionInfoIterator`
1719
* `MongoDB\Model\DatabaseInfoIterator`
1820
* `MongoDB\Model\DatabaseInfoLegacyIterator`
1921
* `MongoDB\Model\IndexInfoIterator`
2022
* `MongoDB\Model\IndexInfoIteratorIterator`
23+
* `MongoDB\Operation\Executable`
2124

2225
GridFS
2326
------

psalm-baseline.xml

-17
Original file line numberDiff line numberDiff line change
@@ -744,23 +744,6 @@
744744
<code><![CDATA[$options['session']]]></code>
745745
</MixedAssignment>
746746
</file>
747-
<file src="src/Operation/MapReduce.php">
748-
<MixedArgument>
749-
<code><![CDATA[$result->result->collection]]></code>
750-
<code><![CDATA[$result->result->db]]></code>
751-
<code><![CDATA[$this->options['typeMap']]]></code>
752-
</MixedArgument>
753-
<MixedAssignment>
754-
<code><![CDATA[$cmd[$option]]]></code>
755-
<code><![CDATA[$options['readConcern']]]></code>
756-
<code><![CDATA[$options['readPreference']]]></code>
757-
<code><![CDATA[$options['session']]]></code>
758-
<code><![CDATA[$options['writeConcern']]]></code>
759-
</MixedAssignment>
760-
<MixedMethodCall>
761-
<code><![CDATA[isInTransaction]]></code>
762-
</MixedMethodCall>
763-
</file>
764747
<file src="src/Operation/ModifyCollection.php">
765748
<MixedArgument>
766749
<code><![CDATA[$this->options['typeMap']]]></code>

src/Collection.php

-48
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Countable;
2121
use Iterator;
2222
use MongoDB\BSON\Document;
23-
use MongoDB\BSON\JavascriptInterface;
2423
use MongoDB\BSON\PackedArray;
2524
use MongoDB\Builder\BuilderEncoder;
2625
use MongoDB\Builder\Pipeline;
@@ -63,7 +62,6 @@
6362
use MongoDB\Operation\InsertOne;
6463
use MongoDB\Operation\ListIndexes;
6564
use MongoDB\Operation\ListSearchIndexes;
66-
use MongoDB\Operation\MapReduce;
6765
use MongoDB\Operation\RenameCollection;
6866
use MongoDB\Operation\ReplaceOne;
6967
use MongoDB\Operation\UpdateMany;
@@ -77,11 +75,7 @@
7775
use function array_key_exists;
7876
use function current;
7977
use function is_array;
80-
use function sprintf;
8178
use function strlen;
82-
use function trigger_error;
83-
84-
use const E_USER_DEPRECATED;
8579

8680
class Collection
8781
{
@@ -908,48 +902,6 @@ public function listSearchIndexes(array $options = []): Iterator
908902
return $operation->execute($server);
909903
}
910904

911-
/**
912-
* Executes a map-reduce aggregation on the collection.
913-
*
914-
* @see MapReduce::__construct() for supported options
915-
* @see https://mongodb.com/docs/manual/reference/command/mapReduce/
916-
* @param JavascriptInterface $map Map function
917-
* @param JavascriptInterface $reduce Reduce function
918-
* @param string|array|object $out Output specification
919-
* @param array $options Command options
920-
* @throws UnsupportedException if options are not supported by the selected server
921-
* @throws InvalidArgumentException for parameter/option parsing errors
922-
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
923-
* @throws UnexpectedValueException if the command response was malformed
924-
*/
925-
public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, string|array|object $out, array $options = []): MapReduceResult
926-
{
927-
@trigger_error(sprintf('The %s method is deprecated and will be removed in a version 2.0.', __METHOD__), E_USER_DEPRECATED);
928-
929-
$hasOutputCollection = ! is_mapreduce_output_inline($out);
930-
931-
// Check if the out option is inline because we will want to coerce a primary read preference if not
932-
if ($hasOutputCollection) {
933-
$options['readPreference'] = new ReadPreference(ReadPreference::PRIMARY);
934-
} else {
935-
$options = $this->inheritReadPreference($options);
936-
}
937-
938-
/* A "majority" read concern is not compatible with inline output, so
939-
* avoid providing the Collection's read concern if it would conflict.
940-
*/
941-
if (! $hasOutputCollection || $this->readConcern->getLevel() !== ReadConcern::MAJORITY) {
942-
$options = $this->inheritReadConcern($options);
943-
}
944-
945-
$options = $this->inheritWriteOptions($options);
946-
$options = $this->inheritTypeMap($options);
947-
948-
$operation = new MapReduce($this->databaseName, $this->collectionName, $map, $reduce, $out, $options);
949-
950-
return $operation->execute(select_server_for_write($this->manager, $options));
951-
}
952-
953905
/**
954906
* Renames the collection.
955907
*

src/MapReduceResult.php

-103
This file was deleted.

0 commit comments

Comments
 (0)