mongoid_frequency adds syntactic sugar for generating frequency maps using the mongodb aggregation framework.
Install directly from rubygems:
gem install mongoid_frequencyOr if you are using a Gemfile, place this in your Gemfile:
gem 'mongoid_frequency'> Book.all.frequency :genre
=> {"Adventure" => 12,
"Sci-fi" => 8,
"Romance" => 4,
"Non-Fiction" => 7}
> Book.collection.freq :genre
=> {"Adventure" => 12,
"Sci-fi" => 8,
"Romance" => 4,
"Non-Fiction" => 7}
> Book.collection.freq :genre, :published.lt => 40.years.ago
=> {"Sci-fi" => 2,
"Romance" => 1}
> author.books.freq :genre
=> {"Romance" => 2,
"Non-Fiction" => 1}- Fork it
- Make your changes
- Write/update tests. Run with
rake. - Issue a Pull Request
MIT. Go nuts.