Browse Source

Options parameter added to "\yii\mogo\Collection::mapReduce()"

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
7314b5fe7e
  1. 17
      extensions/mongo/Collection.php

17
extensions/mongo/Collection.php

@ -522,10 +522,17 @@ class Collection extends Object
* @param string|array $out output collection name. It could be a string for simple output * @param string|array $out output collection name. It could be a string for simple output
* ('outputCollection'), or an array for parametrized output (['merge' => 'outputCollection']) * ('outputCollection'), or an array for parametrized output (['merge' => 'outputCollection'])
* @param array $condition criteria for including a document in the aggregation. * @param array $condition criteria for including a document in the aggregation.
* @param array $options additional optional parameters to the mapReduce command. Valid options include:
* - sort - array - key to sort the input documents. The sort key must be in an existing index for this collection.
* - limit - the maximum number of documents to return in the collection.
* - finalize - function, which follows the reduce method and modifies the output.
* - scope - array - specifies global variables that are accessible in the map, reduce and finalize functions.
* - jsMode - boolean -Specifies whether to convert intermediate data into BSON format between the execution of the map and reduce functions.
* - verbose - boolean - specifies whether to include the timing information in the result information.
* @return string the map reduce output collection name. * @return string the map reduce output collection name.
* @throws Exception on failure. * @throws Exception on failure.
*/ */
public function mapReduce($map, $reduce, $out, $condition = []) public function mapReduce($map, $reduce, $out, $condition = [], $options = [])
{ {
if (!($map instanceof \MongoCode)) { if (!($map instanceof \MongoCode)) {
$map = new \MongoCode((string)$map); $map = new \MongoCode((string)$map);
@ -542,6 +549,14 @@ class Collection extends Object
if (!empty($condition)) { if (!empty($condition)) {
$command['query'] = $this->buildCondition($condition); $command['query'] = $this->buildCondition($condition);
} }
if (array_key_exists('finalize', $options)) {
if (!($options['finalize'] instanceof \MongoCode)) {
$options['finalize'] = new \MongoCode((string)$options['finalize']);
}
}
if (!empty($options)) {
$command = array_merge($command, $options);
}
$token = $this->composeLogToken('mapReduce', [$map, $reduce, $out]); $token = $this->composeLogToken('mapReduce', [$map, $reduce, $out]);
Yii::info($token, __METHOD__); Yii::info($token, __METHOD__);
try { try {

Loading…
Cancel
Save