I am trying to use map_reduce on a collection, via the ruby console , but I am getting "NoMethodError: undefined method `map_reduce' for #
results = Thing.collection.map_reduce(map, reduce, out: "vr")
Map Reduce in Mongoid 3 works slightly differently. The syntax you have would work for the mongo ruby driver. In Mongoid 3, you call this off the class or criteria, like the following:
From a criteria:
Model.where(field: value).map_reduce(map, reduce).out(inline: true)
From a class:
SomeClass.map_reduce(map, reduce).out(replace: "mr-results").each do |document|
#do something
end
You can find more information on this in the Mongoid docs