Lets say
class User
include Mongoid::Document
field :sign_in_count, :type => Integer, :default => 0
field :some_other_count, :type => Integer, :default => 0
end
I need to get a Hash that will consist of sum of both fields
So the result will look like:
{ "sign_in_count" => 4, "some_other_count" => 12 }
If I do
sign_in_sum = User.sum("sign_in_count")
some_other_sum = User.sum("some_other_count")
I see two mongo queries,but I need to do this in one.
Please help.
1 Answer