Ruby 使用mapreduce的输出参数在哪里?

Ruby 使用mapreduce的输出参数在哪里?,ruby,mongodb,mapreduce,Ruby,Mongodb,Mapreduce,这是本教程中的一个代码示例: 他指出,“从MongoDBV1.8开始,您必须指定一个输出集合名称。”但我看不出这是在哪里引用的,也不知道为什么需要它 # Running map-reduce from Ruby (irb) assuming # that @comments references the comments collection # Specify the map and reduce functions in JavaScript, as strings >> m

这是本教程中的一个代码示例:

他指出,“从MongoDBV1.8开始,您必须指定一个输出集合名称。”但我看不出这是在哪里引用的,也不知道为什么需要它

# Running map-reduce from Ruby (irb) assuming
# that @comments references the comments collection

# Specify the map and reduce functions in JavaScript, as strings
>> map    = "function() { emit(this.author, {votes: this.votes}); }"
>> reduce = "function(key, values) { " +
  "var sum = 0; " +
  "values.forEach(function(doc) { " +
  " sum += doc.votes; " +
  "}); " +
  "return {votes: sum}; " +
"};"

# Pass those to the map_reduce helper method
@results = @comments.map_reduce(map, reduce, :out => "mr_results")

# Since this method returns an instantiated results collection,
# we just have to query that collection and iterate over the cursor.
>> @results.find().to_a
=> [{"_id" => "hwaet",   "value"=>{"votes"=>21.0}}, 
    {"_id" => "kbanker", "value"=>{"votes"=>13.0}}
   ]

记录了新的映射/减少输出选项

基本前提是Map/Reduce最初只输出到临时集合。在临时集合中存在一些问题(为什么所有这些都只是为了使它成为临时的?),并且在合并和重新缩减方面添加了一些功能

特别是,您现在可以运行一个M/R,该M/R可以有效地更新以前M/R的输出(可以考虑每小时更新一次每日统计数据,只处理最后一个小时)

但是,如果只需要内存中版本的结果,可以使用inline选项

{out: { inline : 1}}

旁白:你应该考虑使用