Method: Mongoid::Contexts::Enumerable#group
- Defined in:
- lib/mongoid/contexts/enumerable.rb
#group ⇒ Object
Groups the documents by the first field supplied in the field options.
Returns:
A Hash with field values as keys, arrays of documents as values.
67 68 69 70 |
# File 'lib/mongoid/contexts/enumerable.rb', line 67 def group field = [:fields].first documents.group_by { |doc| doc.send(field) } end |