Method: MongoDoc::Contexts::Mongo#aggregate

Defined in:
lib/mongo_doc/contexts/mongo.rb

#aggregateObject

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



25
26
27
# File 'lib/mongo_doc/contexts/mongo.rb', line 25

def aggregate
  collection.group(options[:fields], selector, { :count => 0 }, AGGREGATE_REDUCE, true)
end