【问题标题】:Does Mongoid have Map/Reduce?Mongoid 有 Map/Reduce 吗?
【发布时间】:2010-09-15 23:30:08
【问题描述】:

我正在使用 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 一起使用。

【问题讨论】:

    标签: ruby-on-rails mongodb mapreduce mongoid


    【解决方案1】:

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

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

    有关在 Ruby 驱动程序中执行 map reduce 的一些示例,请参阅 Kyle Banker(Ruby MongoDB 驱动程序的维护者)的this blog post

    【讨论】:

    • hm,所以这是通过使用 MongoDB 的 Ruby 驱动程序走一个较低级别的路线......而不是使用 Mongoid 本身?也许如果 Mongoid 直接拥有它可能会更好......(拥有 Mongoid 是否意味着你也有 Ruby 驱动程序或者它必须是单独的?)截至目前,如果我使用 Analytics.collection 它返回一个 Mongoid::Collection 对象. Analytic.collection.methods.grep /map/ => ["mapreduce", "map_reduce"],所以定义了 map_reduce。
    • Mongoid 运行在 Ruby 驱动之上,使用上面的方法只是将函数传递给 Ruby 驱动。
    • 所以也许 Mongoid 可以把它放到他们的正式文档中吧? Mongoid 使用 Ruby 驱动程序支持 Map/Reduce。
    猜你喜欢
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多