Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

(no description)

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

Defines 1 class

MapReduce:: (5 methods):
  __construct()
  execute()
  createCommand()
  createGetIteratorCallable()
  createOptions()


Class: MapReduce  - X-Ref

Operation for the mapReduce command.

__construct($databaseName, $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.

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

* 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.

For servers < 3.2, this option is ignored as document level validation
is not available.

* collation (document): Collation specification.

This is not supported for server versions < 3.4 and will result in an
exception at execution time if used.

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

* 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.

This is not supported for server versions < 3.2 and will result in an
exception at execution time if used.

* 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.

Sessions are not supported for server versions < 3.6.

* 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.

This is not supported for server versions < 3.4 and will result in an
exception at execution time if used.

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.

param: Server $server
return: MapReduceResult

createCommand(Server $server)   X-Ref
Create the mapReduce command.

param: Server $server
return: Command

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

param: stdClass $result
param: Server   $server
return: callable

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

param: boolean $hasOutputCollection
return: array