# File lib/mongoid/contexts/mongo.rb, line 362 def grouped(start, field, reduce) collection = klass.collection.group( :cond => selector, :initial => { start => "start" }, :reduce => reduce.gsub("[field]", field) ) value = collection.empty? ? nil : collection.first[start.to_s] value && value.do_or_do_not(:nan?) ? nil : value end