Module: Mongoid::MapReduce::ClassMethods

Defined in:
lib/mongoid/mapreduce/base.rb

Instance Method Summary collapse

Instance Method Details

#map_reduce(map_key = :_id, options = {}, &block) ⇒ Object

Run a map/reduce operation on the current model

map_key: Symbol or String, the field used in the map function

Returns a Hash of results



13
14
15
16
17
18
# File 'lib/mongoid/mapreduce/base.rb', line 13

def map_reduce(map_key=:_id, options={}, &block)
  options[:map_key] = map_key
  reducer = Reducer.new(self, criteria.selector, options)
  reducer.instance_eval(&block) if block.present?
  reducer.run
end