17

我正在使用 Ruby 代码从 Mongoid 返回的数组中计算总和。

但也许使用 Map/Reduce 可以更快,除了我在 mongoid.org 和 Google 上没有看到任何 Map Reduce 文档

map reduce site:mongoid.org

也不给出任何结果。(或使用MapReduceMap/Reduce

MongoDB 的网站上有文档

map reduce site:mongodb.org

但也需要将 Map Reduce 与 Mongoid 一起使用。

4

1 回答 1

21

您可以像直接通过 Ruby 驱动程序一样将 map reduce 与 Mongoid 一起使用:

# Post is a Mongoid model...
Post.collection.map_reduce(map_function, reduce_function, options)

有关在 Ruby 驱动程序中执行 map reduce 的一些示例,请参阅Kyle Banker(Ruby MongoDB 驱动程序的维护者)的这篇博客文章

于 2010-09-16T00:33:23.780 回答