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 behavior 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 Loggable
Instance Attribute Summary collapse
-
#map_function ⇒ String
readonly
Map The map function.
-
#reduce_function ⇒ 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.
-
#execute ⇒ Mongo::Operation::Result
Execute the map reduce, without doing a fetch query to retrieve the results if outputted to a collection.
-
#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_one_retry, #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.
107 108 109 110 111 112 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 107 def initialize(view, map, reduce, = {}) @view = view @map_function = map.freeze @reduce_function = reduce.freeze = BSON::Document.new().freeze end |
Instance Attribute Details
#map_function ⇒ String (readonly)
Returns map The map function.
44 45 46 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 44 def map_function @map_function end |
#reduce_function ⇒ String (readonly)
Returns reduce The reduce function.
47 48 49 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 47 def reduce_function @reduce_function 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 79 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 67 def each @cursor = nil session = client.send(:get_session, ) legacy_write_with_retry do |server| result = send_initial_query(server, session) result = send_fetch_query(server, session) unless inline? @cursor = Cursor.new(view, result, server, session: session) end @cursor.each do |doc| yield doc end if block_given? @cursor.to_enum end |
#execute ⇒ Mongo::Operation::Result
Execute the map reduce, without doing a fetch query to retrieve the results
if outputted to a collection.
193 194 195 196 197 198 199 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 193 def execute view.send(:with_session, ) do |session| legacy_write_with_retry do |server| send_initial_query(server, session) end end end |
#finalize(function = nil) ⇒ MapReduce, String
Set or get the finalize function for the operation.
92 93 94 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 92 def finalize(function = nil) configure(:finalize, function) end |
#js_mode(value = nil) ⇒ MapReduce, ...
Set or get the jsMode flag for the operation.
125 126 127 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 125 def js_mode(value = nil) configure(:js_mode, value) end |
#out(location = nil) ⇒ MapReduce, Hash
Set or get the output location for the operation.
149 150 151 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 149 def out(location = nil) configure(:out, location) end |
#scope(object = nil) ⇒ MapReduce, Hash
Set or get a scope on the operation.
164 165 166 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 164 def scope(object = nil) configure(:scope, object) end |
#verbose(value = nil) ⇒ MapReduce, Hash
Whether to include the timing information in the result.
180 181 182 |
# File 'lib/mongo/collection/view/map_reduce.rb', line 180 def verbose(value = nil) configure(:verbose, value) end |