Moodle PHP Documentation 4.1
Moodle 4.1.11 (Build: 20240610) (c8c84b4af18)
MongoDB\Operation\MapReduce Class Reference
Inheritance diagram for MongoDB\Operation\MapReduce:
MongoDB\Operation\Executable

Public Member Functions

 __construct (string $databaseName, string $collectionName, JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options=[])
 Constructs a mapReduce command.
 
 execute (Server $server)
 Execute the operation.
 

Constructor & Destructor Documentation

◆ __construct()

MongoDB\Operation\MapReduce::__construct ( string $databaseName,
string $collectionName,
JavascriptInterface $map,
JavascriptInterface $reduce,
$out,
array $options = [] )

Constructs a mapReduce command.

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.
  • comment (mixed): BSON value to attach as a comment to this command.

    This is not supported for servers versions < 4.4.

  • 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
string$databaseNameDatabase name
string$collectionNameCollection name
JavascriptInterface$mapMap function
JavascriptInterface$reduceReduce function
string | array | object$outOutput specification
array$optionsCommand options
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors

Member Function Documentation

◆ execute()

MongoDB\Operation\MapReduce::execute ( Server $server)

Execute the operation.

See also
Executable\execute()
Return values
MapReduceResult
Exceptions
UnexpectedValueExceptionif the command response was malformed
UnsupportedExceptionif read concern or write concern is used and unsupported
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

Implements MongoDB\Operation\Executable.


The documentation for this class was generated from the following file: