Method: MongoDoc::Contexts::Mongo#sum
- Defined in:
- lib/mongodoc/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.
197 198 199 |
# File 'lib/mongodoc/contexts/mongo.rb', line 197 def sum(field) grouped(:sum, field.to_s, SUM_REDUCE) end |