MapReduce framework for MongoDB using Ruby DSL
Add this line to your application's Gemfile:
gem 'mr_mongo'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mr_mongo
$ bundle exec mr_mongo
Commands:
mr_mongo exec # executes MapReduce
mr_mongo exec_on_memory # executes MapReduce on memory
mr_mongo help [COMMAND] # Describe available commands or one specific command
NOTICE
The result of exec_on_memory may be massive, so it's preferable to use for small collections as testing.
Following is word-count example using Mr. Mongo DSL
set :collection, 'texts'
set :out, {replace: 'word_counts'}
__END__
@@ map
function () {
this.text.split(/\s+/).forEach(function (word) {
emit(word, {count: 1});
});
}
@@ reduce
function (key, values) {
var count = 0;
values.forEach(function (value) {
count += value.count;
});
return {count: count};
}
sub-commands exec
and exec_on_memory
accepts Dynamic Parameters by --params
option.
--params
can be specified as JSON hash.
$ bundle exec mr_mongo exec some_map_reduce.rb --params '{"date":"2013-02-01"}'
In DSL, Dynamic Parameters can be get with #params
method.
set :collection, 'accesses'
set :query, {date: params['date']} if params['date']
__END__
...
Default Parameter can be set with #default_param
method
default_param 'date', '2013-02-01'
# => params will be {"date" => "2013-02-01"} by default.
- Fork it
- 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