Class: Mongo::Collection::View::MapReduce
- Inherits:
-
Object
- Object
- Mongo::Collection::View::MapReduce
- Extended by:
- Forwardable
- Defined in:
- lib/mongo/collection/view/map_reduce.rb
Overview
Provides behaviour around a map/reduce operation on the collection view.
Constant Summary collapse
- INLINE =
The inline option.
'inline'.freeze
- REROUTE =
Reroute message.
'Rerouting the MapReduce operation to the primary server.'.freeze
Constants included from Retryable
Retryable::COULD_NOT_CONTACT_PRIMARY, Retryable::NOT_MASTER
Constants included from Loggable
Instance Attribute Summary collapse
-
#map ⇒ String
readonly
Map The map function.
-
#reduce ⇒ String
readonly
Reduce The reduce function.
-
#view ⇒ View
readonly
View The collection view.
Attributes included from Immutable
Instance Method Summary collapse
-
#each {|Each| ... } ⇒ Enumerator
Iterate through documents returned by the map/reduce.
-
#finalize(function = nil) ⇒ MapReduce, String
Set or get the finalize function for the operation.
-
#initialize(view, map, reduce, options = {}) ⇒ MapReduce
constructor
Initialize the map/reduce for the provided collection view, functions and options.
-
#js_mode(value = nil) ⇒ MapReduce, ...
Set or get the jsMode flag for the operation.
-
#out(location = nil) ⇒ MapReduce, Hash
Set or get the output location for the operation.
-
#scope(object = nil) ⇒ MapReduce, Hash
Set or get a scope on the operation.
-
#verbose(value = nil) ⇒ MapReduce, Hash
Whether to include the timing information in the result.
Methods included from Retryable
#read_with_retry, #write_with_retry
Methods included from Loggable
#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger
Constructor Details
#initialize(view, map, reduce, options = {}) ⇒ MapReduce
Initialize the map/reduce for the provided collection view, functions and options.
106 107 108 109 110 111 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 106 def initialize(view, map, reduce, = {}) @view = view @map = map.freeze @reduce = reduce.freeze @options = .freeze end |
Instance Attribute Details
#map ⇒ String (readonly)
Returns map The map function.
44 45 46 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 44 def map @map end |
#reduce ⇒ String (readonly)
Returns reduce The reduce function.
47 48 49 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 47 def reduce @reduce end |
#view ⇒ View (readonly)
Returns view The collection view.
41 42 43 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 41 def view @view end |
Instance Method Details
#each {|Each| ... } ⇒ Enumerator
Iterate through documents returned by the map/reduce.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 67 def each @cursor = nil write_with_retry do server = read.select_server(cluster, false) result = send_initial_query(server) @cursor = Cursor.new(view, result, server) end @cursor.each do |doc| yield doc end if block_given? @cursor.to_enum end |
#finalize(function = nil) ⇒ MapReduce, String
Set or get the finalize function for the operation.
91 92 93 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 91 def finalize(function = nil) configure(:finalize, function) end |
#js_mode(value = nil) ⇒ MapReduce, ...
Set or get the jsMode flag for the operation.
124 125 126 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 124 def js_mode(value = nil) configure(:js_mode, value) end |
#out(location = nil) ⇒ MapReduce, Hash
Set or get the output location for the operation.
148 149 150 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 148 def out(location = nil) configure(:out, location) end |
#scope(object = nil) ⇒ MapReduce, Hash
Set or get a scope on the operation.
163 164 165 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 163 def scope(object = nil) configure(:scope, object) end |
#verbose(value = nil) ⇒ MapReduce, Hash
Whether to include the timing information in the result.
179 180 181 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 179 def verbose(value = nil) configure(:verbose, value) end |