Method: MongoDoc::Contexts::Mongo#group
- Defined in:
- lib/mongo_doc/contexts/mongo.rb
#group ⇒ Object
Groups 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 objects.
Example:
context.group
Returns:
A Hash with field values as keys, arrays of documents as values.
117 118 119 120 121 122 123 124 125 |
# File 'lib/mongo_doc/contexts/mongo.rb', line 117 def group collection.group( [:fields], selector, { :group => [] }, GROUP_REDUCE, true ).collect {|docs| docs["group"] = MongoDoc::BSON.decode(docs["group"]); docs } end |