Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

(no description)

File Size: 418 lines (17 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

MapReduce:: (6 methods):
  __construct()
  execute()
  checkOutDeprecations()
  createCommand()
  createGetIteratorCallable()
  createOptions()


Class: MapReduce  - X-Ref

Operation for the mapReduce command.

__construct(string $databaseName, string $collectionName, JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options = [])   X-Ref
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.

param: string              $databaseName   Database name
param: string              $collectionName Collection name
param: JavascriptInterface $map            Map function
param: JavascriptInterface $reduce         Reduce function
param: string|array|object $out            Output specification
param: array               $options        Command options

execute(Server $server)   X-Ref
Execute the operation.

return: MapReduceResult

checkOutDeprecations($out)   X-Ref

param: string|array|object $out

createCommand()   X-Ref
Create the mapReduce command.


createGetIteratorCallable(stdClass $result, Server $server)   X-Ref
Creates a callable for MapReduceResult::getIterator().


createOptions(bool $hasOutputCollection)   X-Ref
Create options for executing the command.