Class Mongo::Collection::View::MapReduce
In: lib/mongo/collection/view/map_reduce.rb
Parent: Object

Provides behavior around a map/reduce operation on the collection view.

@since 2.0.0

Methods

each   execute   finalize   js_mode   new   out   scope   verbose  

Included Modules

Enumerable Immutable Loggable Retryable

Constants

INLINE = 'inline'.freeze   The inline option.

@since 2.1.0

REROUTE = 'Rerouting the MapReduce operation to the primary server.'.freeze   Reroute message.

@since 2.1.0

Attributes

map_function  [R]  @return [ String ] map The map function.
reduce_function  [R]  @return [ String ] reduce The reduce function.
view  [R]  @return [ View ] view The collection view.

Public Class methods

Initialize the map/reduce for the provided collection view, functions and options.

@example Create the new map/reduce view.

@param [ Collection::View ] view The collection view. @param [ String ] map The map function. @param [ String ] reduce The reduce function. @param [ Hash ] options The map/reduce options.

@since 2.0.0

Public Instance methods

Iterate through documents returned by the map/reduce.

@example Iterate through the result of the map/reduce.

  map_reduce.each do |document|
    p document
  end

@return [ Enumerator ] The enumerator.

@since 2.0.0

@yieldparam [ Hash ] Each matching document.

Execute the map reduce, without doing a fetch query to retrieve the results

  if outputted to a collection.

@example Execute the map reduce and get the raw result.

  map_reduce.execute

@return [ Mongo::Operation::Result ] The raw map reduce result

@since 2.5.0

Set or get the finalize function for the operation.

@example Set the finalize function.

  map_reduce.finalize(function)

@param [ String ] function The finalize js function.

@return [ MapReduce, String ] The new MapReduce operation or the

  value of the function.

@since 2.0.0

Set or get the jsMode flag for the operation.

@example Set js mode for the operation.

  map_reduce.js_mode(true)

@param [ true, false ] value The jsMode value.

@return [ MapReduce, true, false ] The new MapReduce operation or the

  value of the jsMode flag.

@since 2.0.0

Set or get the output location for the operation.

@example Set the output to inline.

  map_reduce.out(inline: 1)

@example Set the output collection to merge.

  map_reduce.out(merge: 'users')

@example Set the output collection to replace.

  map_reduce.out(replace: 'users')

@example Set the output collection to reduce.

  map_reduce.out(reduce: 'users')

@param [ Hash ] location The output location details.

@return [ MapReduce, Hash ] The new MapReduce operation or the value

  of the output location.

@since 2.0.0

Set or get a scope on the operation.

@example Set the scope value.

  map_reduce.scope(value: 'test')

@param [ Hash ] object The scope object.

@return [ MapReduce, Hash ] The new MapReduce operation or the value

  of the scope.

@since 2.0.0

Whether to include the timing information in the result.

@example Set the verbose value.

  map_reduce.verbose(false)

@param [ true, false ] value Whether to include timing information

  in the result.

@return [ MapReduce, Hash ] The new MapReduce operation or the value

  of the verbose option.

@since 2.0.5

[Validate]