【发布时间】:2012-06-28 12:21:14
【问题描述】:
当我在 rails 中使用 mongoid mapreduce 时,我通过字符串传递 map 和 reduce 函数。例如
def group
Order.collection.map_reduce(map, reduce, :out => 'output_collection')
end
def map
"function()
{
var key = {game_id: this.game_id, year: this.date.getFullYear()};
emit(key, {count: 1, score: this.score});
}"
end
def reduce
"function()
{
var result = {sum: 0, total_score: 0, average: 0};
values.forEach(function(value)
{
result.sum += value.count;
result.total_score += value.score;
});
}"
end
是否可以在 rails 中测试 map 和 reduce 功能。 这是一个简单的例子。但是我的项目功能比较复杂,我觉得很难维护。
感谢您提供任何建议。
【问题讨论】:
标签: ruby-on-rails mongodb testing mapreduce