-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
sum/avg will return either nil, NaN or the resulting number. If any of the records that are being map/reduced don't have the field you're working on, it will always return NaN regardless. It's trivial to work around, but it seems like Mongoid should be checking to make sure the field is at least undefined/nil before trying to use it.
class Foobar
include Mongoid::Document
field :pending, :type => Integer
end
Foobar.create(:pending => 5)
Foobar.create(:pending => nil)
Foobar.sum(:pending) # NaN