Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

(no description)

File Size: 460 lines (19 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($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.

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.

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.

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.

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

checkOutDeprecations($out)   X-Ref

param: string|array|object $out
return: void

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