Method: MongoDoc::Contexts::Mongo#aggregate
- Defined in:
- lib/mongodoc/contexts/mongo.rb
#aggregate ⇒ Object
Aggregate 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 counts.
Example:
context.aggregate
Returns:
A Hash with field values as keys, counts as values
23 24 25 |
# File 'lib/mongodoc/contexts/mongo.rb', line 23 def aggregate collection.group([:fields], selector, { :count => 0 }, AGGREGATE_REDUCE, true) end |