Mongodb 版本2中Mongoid条件的映射/减少操作

Mongodb 版本2中Mongoid条件的映射/减少操作,mongodb,mapreduce,mongoid,Mongodb,Mapreduce,Mongoid,MongoDB map/reduce功能在Mongoid版本2的Mongoid标准上不可用,我说的对吗+ 有人能证实这一点吗?我有一个标准 这是我的问题 class PerformerSource scope :active_performers,where(:active => true).only([:performer_id, :sort_order,:stage_name, :photo, :large_photo, :status, :current_performance_

MongoDB map/reduce功能在Mongoid版本2的Mongoid标准上不可用,我说的对吗+

有人能证实这一点吗?我有一个标准

这是我的问题

class PerformerSource
  scope :active_performers,where(:active => true).only([:performer_id, :sort_order,:stage_name, :photo, :large_photo, :status, :current_performance_type,:current_sign_in_at])
end
PerformerSource.active\u performers.order\u by([:sort\u order,:desc])

我想对它应用map/reduce函数

像这样的

PerformerSource.active_performers.order_by([:sort_order,:desc]).map_reduce(PerformerSource.map,PerformerSource.reduce)
但每当我这样做时,它就会返回错误

NoMethodError:for#的未定义方法“map_reduce”

检查map/reduce是否可用

PerformerSource.active_performers.order_by([:sort_order,:desc]).respond_to?(:map_reduce)
=> false

PerformerSource.respond_to?(:map_reduce)
=> false
所以我的想法正确吗?因为我看到Mongoid-3在Mongoid标准中添加了map/reduce,但在Mongoid 2中找不到相同的

我可以升级mongoid(我希望可以),因为应用程序运行在Ruby-1.8.7上,mongoid 3需要Ruby-1.9+

因此,如果map/reduce不适用于如何运行map/reduce的标准,请允许我考虑其他条件,即
active\u performers.order\u by([:sort\u order,:desc])


注意:为了清楚起见,我没有添加映射减少功能

我制作了以下猴子补丁,我正在制作中使用:


module Mongoid

  module Criterion #:nodoc:
    module MapReduce
      def map_reduce(map, reduce, options = {})
        opts = {:out => {:inline => 1}, :raw => true, :query => selector}.merge(options)
        klass.collection.map_reduce(map, reduce, opts)
      end
      alias :mapreduce :map_reduce
    end
  end

end

这样我就可以在一个条件上执行map reduce。如果你想在所有人身上执行它,那么可以使用.all或.scoped(我更喜欢),比如PerformerSource.scoped.map\u reduce(…)

我怀疑它会根据附加到它的条件触发一个命令,比如'Performer.active\u performers.order\u by([:sort\u order,:desc])。map\u reduce纠正我,如果我错了,我真的不明白你在这里说的话。顺便说一句,除非你限制结果的数量,否则顺序真的没有什么意义。我说过你在附加一个map reduce函数,它将
klass.collection
返回结果
Performer.active\u performers.order\u by([:sort\u order,:desc])
定义并在其上进一步操作map reduce的条件map\u reduce后的条件将使workklass.collection.map\u reduce作为:查询参数接收原始选择器。