Documentation

MapReduce
in package
implements Executable

Operation for the mapReduce command.

Tags
see
Collection::mapReduce()
see
https://docs.mongodb.com/manual/reference/command/mapReduce/

Interfaces, Classes, Traits and Enums

Executable

Table of Contents

$collectionName  : string
$databaseName  : string
$map  : JavascriptInterface
$options  : array<string|int, mixed>
$out  : array<string|int, mixed>|object|string
$reduce  : JavascriptInterface
__construct()  : mixed
Constructs a mapReduce command.
execute()  : MapReduceResult
Execute the operation.
checkOutDeprecations()  : void
createCommand()  : Command
Create the mapReduce command.
createGetIteratorCallable()  : callable
Creates a callable for MapReduceResult::getIterator().
createOptions()  : array<string|int, mixed>
Create options for executing the command.

Properties

$collectionName

private string $collectionName

$options

private array<string|int, mixed> $options

$out

private array<string|int, mixed>|object|string $out

Methods

__construct()

Constructs a mapReduce command.

public __construct(string $databaseName, string $collectionName, JavascriptInterface $map, JavascriptInterface $reduce, string|array<string|int, mixed>|object $out[, array<string|int, mixed> $options = [] ]) : mixed

Required arguments:

  • map (MongoDB\BSON\Javascript): A JavaScript function that associates or "maps" a value with a key and emits the key and value pair.

    Passing a Javascript instance with a scope is deprecated. Put all scope variables in the "scope" option of the MapReduce operation.

  • reduce (MongoDB\BSON\Javascript): A JavaScript function that "reduces" to a single object all the values associated with a particular key.

    Passing a Javascript instance with a scope is deprecated. Put all scope variables in the "scope" option of the MapReduce operation.

  • out (string|document): Specifies where to output the result of the map-reduce operation. You can either output to a collection or return the result inline. On a primary member of a replica set you can output either to a collection or inline, but on a secondary, only inline output is possible.

Supported options:

  • bypassDocumentValidation (boolean): If true, allows the write to circumvent document level validation. This only applies when results are output to a collection.

  • collation (document): Collation specification.

  • finalize (MongoDB\BSON\JavascriptInterface): Follows the reduce method and modifies the output.

    Passing a Javascript instance with a scope is deprecated. Put all scope variables in the "scope" option of the MapReduce operation.

  • jsMode (boolean): Specifies whether to convert intermediate data into BSON format between the execution of the map and reduce functions.

  • limit (integer): Specifies a maximum number of documents for the input into the map function.

  • maxTimeMS (integer): The maximum amount of time to allow the query to run.

  • query (document): Specifies the selection criteria using query operators for determining the documents input to the map function.

  • readConcern (MongoDB\Driver\ReadConcern): Read concern. This is not supported when results are returned inline.

  • readPreference (MongoDB\Driver\ReadPreference): Read preference.

    This option is ignored if results are output to a collection.

  • scope (document): Specifies global variables that are accessible in the map, reduce and finalize functions.

  • session (MongoDB\Driver\Session): Client session.

  • sort (document): Sorts the input documents. This option is useful for optimization. For example, specify the sort key to be the same as the emit key so that there are fewer reduce operations. The sort key must be in an existing index for this collection.

  • typeMap (array): Type map for BSON deserialization. This will be applied to the returned Cursor (it is not sent to the server).

  • verbose (boolean): Specifies whether to include the timing information in the result information.

  • writeConcern (MongoDB\Driver\WriteConcern): Write concern. This only applies when results are output to a collection.

Parameters
$databaseName : string

Database name

$collectionName : string

Collection name

$map : JavascriptInterface

Map function

$reduce : JavascriptInterface

Reduce function

$out : string|array<string|int, mixed>|object

Output specification

$options : array<string|int, mixed> = []

Command options

Tags
throws
InvalidArgumentException

for parameter/option parsing errors

Return values
mixed

checkOutDeprecations()

private checkOutDeprecations(string|array<string|int, mixed>|object $out) : void
Parameters
$out : string|array<string|int, mixed>|object
Return values
void

createCommand()

Create the mapReduce command.

private createCommand() : Command
Return values
Command

createGetIteratorCallable()

Creates a callable for MapReduceResult::getIterator().

private createGetIteratorCallable(stdClass $result, Server $server) : callable
Parameters
$result : stdClass
$server : Server
Tags
throws
UnexpectedValueException

if the command response was malformed

Return values
callable

Search results