【发布时间】:2012-10-15 06:43:25
【问题描述】:
我是否正确,因为 MongoId 版本 2+ 的 Mongoid Criteria 上没有 MongoDB map/reduce 功能
谁能证实我有一个标准
这里是我的查询
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_performers.order_by([:sort_order,:desc])
我想对其应用 map/reduce 功能
类似的东西
PerformerSource.active_performers.order_by([:sort_order,:desc]).map_reduce(PerformerSource.map,PerformerSource.reduce)
但每当我这样做时,它都会返回错误
NoMethodError: 未定义方法 `map_reduce' for #
检查 map/reduce 是否可用
PerformerSource.active_performers.order_by([:sort_order,:desc]).respond_to?(:map_reduce)
=> false
PerformerSource.respond_to?(:map_reduce)
=> false
所以我相信我是正确的,因为我看到 Mongoid-3 提供了在 here 上的 Mongoid-criteria 中添加 map/reduce 的规定,但在 mongoid 2 中找不到相同的内容
我可以升级 mongoid(我希望可以),因为应用程序在 Ruby-1.8.7 上运行并且 mongoid 3 需要 ruby-1.9+
如果 map/reduce 不能按照如何运行 map/reduce 的标准工作,那么可以让我考虑其他条件,即
active_performers.order_by([:sort_order,:desc])
注意:我只是为了清楚起见没有添加 map 和 reduce 功能
【问题讨论】: