Class: Mongoid::Contextual::MapReduce
- Inherits:
-
Object
- Object
- Mongoid::Contextual::MapReduce
- Includes:
- Enumerable, Command
- Defined in:
- lib/mongoid/contextual/map_reduce.rb
Instance Method Summary collapse
-
#counts ⇒ Hash
Get all the counts returned by the map/reduce.
-
#each ⇒ Enumerator
Iterates over each of the documents in the map/reduce, excluding the extra information that was passed back from the database.
-
#emitted ⇒ Integer
Get the number of documents emitted by the map/reduce.
-
#finalize(function) ⇒ MapReduce
Provide a finalize js function for the map/reduce.
-
#initialize(criteria, map, reduce) ⇒ MapReduce
constructor
Initialize the new map/reduce directive.
-
#input ⇒ Integer
Get the number of documents that were input into the map/reduce.
-
#js_mode ⇒ MapReduce
Sets the map/reduce to use jsMode.
-
#out(location) ⇒ MapReduce
Specifies where the map/reduce output is to be stored.
-
#output ⇒ Integer
Get the number of documents output by the map/reduce.
-
#raw ⇒ Hash
Get the raw output from the map/reduce operation.
-
#reduced ⇒ Integer
Get the number of documents reduced by the map/reduce.
-
#scope(object) ⇒ MapReduce
Adds a javascript object to the global scope of the map/reduce.
-
#time ⇒ Float
Get the execution time of the map/reduce.
Methods included from Command
Constructor Details
#initialize(criteria, map, reduce) ⇒ MapReduce
Initialize the new map/reduce directive.
81 82 83 84 85 86 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 81 def initialize(criteria, map, reduce) @criteria = criteria command[:mapreduce] = criteria.klass.collection_name.to_s command[:map], command[:reduce] = map, reduce end |
Instance Method Details
#counts ⇒ Hash
Get all the counts returned by the map/reduce.
19 20 21 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 19 def counts results["counts"] end |
#each ⇒ Enumerator
Iterates over each of the documents in the map/reduce, excluding the extra information that was passed back from the database.
34 35 36 37 38 39 40 41 42 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 34 def each if block_given? documents.each do |doc| yield doc end else to_enum end end |
#emitted ⇒ Integer
Get the number of documents emitted by the map/reduce.
52 53 54 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 52 def emitted counts["emit"] end |
#finalize(function) ⇒ MapReduce
Provide a finalize js function for the map/reduce.
66 67 68 69 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 66 def finalize(function) command[:finalize] = function self end |
#input ⇒ Integer
Get the number of documents that were input into the map/reduce.
96 97 98 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 96 def input counts["input"] end |
#js_mode ⇒ MapReduce
Sets the map/reduce to use jsMode.
108 109 110 111 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 108 def js_mode command[:jsMode] = true self end |
#out(location) ⇒ MapReduce
Specifies where the map/reduce output is to be stored.
132 133 134 135 136 137 138 139 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 132 def out(location) normalized = location.dup normalized.update_values do |value| value.is_a?(::Symbol) ? value.to_s : value end command[:out] = normalized self end |
#output ⇒ Integer
Get the number of documents output by the map/reduce.
149 150 151 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 149 def output counts["output"] end |
#raw ⇒ Hash
Get the raw output from the map/reduce operation.
161 162 163 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 161 def raw results end |
#reduced ⇒ Integer
Get the number of documents reduced by the map/reduce.
173 174 175 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 173 def reduced counts["reduce"] end |
#scope(object) ⇒ MapReduce
Adds a javascript object to the global scope of the map/reduce.
187 188 189 190 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 187 def scope(object) command[:scope] = object self end |
#time ⇒ Float
Get the execution time of the map/reduce.
200 201 202 |
# File 'lib/mongoid/contextual/map_reduce.rb', line 200 def time results["timeMillis"] end |