Method: MongoDoc::Contexts::Mongo#sum
- Defined in:
- lib/mongo_doc/contexts/mongo.rb
#sum(field) ⇒ Object
Sum the context.
This will take the internally built selector and options and pass them on to the Ruby driver’s group() method on the collection. The collection itself will be retrieved from the class provided, and once the query has returned it will provided a grouping of keys with sums.
Example:
context.sum(:age)
Returns:
A numeric value that is the sum.
239 240 241 |
# File 'lib/mongo_doc/contexts/mongo.rb', line 239 def sum(field) grouped(:sum, field.to_s, SUM_REDUCE) end |