Mongoid Report
Library for easy building aggregation report using mongodb aggregation framework.
Example
class Model
include Mongoid::Document
field :field1, type: Integer, default: 0
field :day, type: Date
end
class Report1
include Mongoid::Report
aggregation_field :field1, for: Model
end
class Report2
include Mongoid::Report
attach_to Model do
aggregation_field :field1
end
end
class Report3
include Mongoid::Report
group_by :day, for: Model
aggregation_field :field1, for: Model
end
class Report4
include Mongoid::Report
attach_to Model do
group_by :day
aggregation_field :field1
end
end
class Report5
include Mongoid::Report
attach_to Model, as: 'summary-report' do
group_by :day
aggregation_field :field1
end
end
example = Report4.new
scope = example.aggregate_for(Model)
scope = scope.query('match' => { 'field1' => 1 })
result = scope.all
result.is_a?(Array) => true
result[0].is_a?(Hash) => true
example = Report5.new
scope = example.aggregate_for('summary-report')
result = scope.all
Installation
Add this line to your application's Gemfile:
gem 'mongoid-report'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mongoid-report
Contributors
@oivoodoo
@baltazore
Contributing
- Fork it ( http://github.com/oivoodoo/mongoid-report/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request

