public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options = [])
    {
        $hasOutputCollection = ! \MongoDB\is_mapreduce_output_inline($out);

        if ( ! isset($options['readPreference'])) {
            $options['readPreference'] = $this->readPreference;
        }

        // 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::RP_PRIMARY);
        }

        $server = $this->manager->selectServer($options['readPreference']);

        /* A "majority" read concern is not compatible with inline output, so
         * avoid providing the Collection's read concern if it would conflict.
         *
         * A read concern is also not compatible with transactions.
         */
        if ( ! isset($options['readConcern']) && ! ($hasOutputCollection && $this->readConcern->getLevel() === ReadConcern::MAJORITY) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) && ! $this->isInTransaction($options)) {
            $options['readConcern'] = $this->readConcern;
        }

        if ( ! isset($options['typeMap'])) {
            $options['typeMap'] = $this->typeMap;
        }

        if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! $this->isInTransaction($options)) {
            $options['writeConcern'] = $this->writeConcern;
        }

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

        return $operation->execute($server);
    }
public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options = [])
    {
        $hasOutputCollection = ! \MongoDB\is_mapreduce_output_inline($out);

        if ( ! isset($options['readPreference'])) {
            $options['readPreference'] = $this->readPreference;
        }

        // 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::RP_PRIMARY);
        }

        $server = $this->manager->selectServer($options['readPreference']);

        /* A "majority" read concern is not compatible with inline output, so
         * avoid providing the Collection's read concern if it would conflict.
         *
         * A read concern is also not compatible with transactions.
         */
        if ( ! isset($options['readConcern']) && ! ($hasOutputCollection && $this->readConcern->getLevel() === ReadConcern::MAJORITY) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) && ! $this->isInTransaction($options)) {
            $options['readConcern'] = $this->readConcern;
        }

        if ( ! isset($options['typeMap'])) {
            $options['typeMap'] = $this->typeMap;
        }

        if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! $this->isInTransaction($options)) {
            $options['writeConcern'] = $this->writeConcern;
        }

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

        return $operation->execute($server);
    }
public function mapReduce ( JavascriptInterface $ map , JavascriptInterface $ reduce , $ out , array $ options = [ ] ) { $ hasOutputCollection = ! \ MongoDB \ is_mapreduce_output_inline ( $ out ) ; if ( ! isset ( $ options [ 'readPreference' ] ) ) { $ options [ 'readPreference' ] = $ this -> readPreference ; } // 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 :: RP_PRIMARY ) ; } $ server = $ this -> manager -> selectServer ( $ options [ 'readPreference' ] ) ; /* A "majority" read concern is not compatible with inline output, so
         * avoid providing the Collection's read concern if it would conflict.
         *
         * A read concern is also not compatible with transactions.
         */ if ( ! isset ( $ options [ 'readConcern' ] ) && ! ( $ hasOutputCollection && $ this -> readConcern -> getLevel ( ) === ReadConcern :: MAJORITY ) && \ MongoDB \ server_supports_feature ( $ server , self :: $ wireVersionForReadConcern ) && ! $ this -> isInTransaction ( $ options ) ) { $ options [ 'readConcern' ] = $ this -> readConcern ; } if ( ! isset ( $ options [ 'typeMap' ] ) ) { $ options [ 'typeMap' ] = $ this -> typeMap ; } if ( ! isset ( $ options [ 'writeConcern' ] ) && \ MongoDB \ server_supports_feature ( $ server , self :: $ wireVersionForWritableCommandWriteConcern ) && ! $ this -> isInTransaction ( $ options ) ) { $ options [ 'writeConcern' ] = $ this -> writeConcern ; } $ operation = new MapReduce ( $ this -> databaseName , $ this -> collectionName , $ map , $ reduce , $ out , $ options ) ; return $ operation -> execute ( $ server ) ; }
Executes a map-reduce aggregation on the collection.

@see MapReduce::__construct() for supported options
@see http://docs.mongodb.org/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
@return MapReduceResult
@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
Executes a map - reduce aggregation on the collection .