Module: Mongoid::Frequency
- Extended by:
- Frequency
- Included in:
- Frequency
- Defined in:
- lib/mongoid_frequency/query.rb,
lib/mongoid_frequency/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
Instance Method Details
#query(collection, match, group) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mongoid_frequency/query.rb', line 5 def query(collection, match, group) collection.aggregate([ { '$match' => match }, { '$group' => { _id: ensure_bling(group), count: { '$sum' => 1 } } } ]).each_with_object({}) do |element, h| h[element['_id']] = element['count'] end end |