【发布时间】:2012-11-30 03:42:26
【问题描述】:
我正在尝试通过 ruby 控制台在集合上使用 map_reduce,但我收到“NoMethodError: undefined method `map_reduce' for #
results = Thing.collection.map_reduce(map, reduce, out: "vr")
【问题讨论】:
我正在尝试通过 ruby 控制台在集合上使用 map_reduce,但我收到“NoMethodError: undefined method `map_reduce' for #
results = Thing.collection.map_reduce(map, reduce, out: "vr")
【问题讨论】:
Mongoid 3 中的 Map Reduce 的工作方式略有不同。您拥有的语法适用于 mongo ruby 驱动程序。在 Mongoid 3 中,您将其从类或标准中调用,如下所示:
从一个标准:
Model.where(field: value).map_reduce(map, reduce).out(inline: true)
来自一个班级:
SomeClass.map_reduce(map, reduce).out(replace: "mr-results").each do |document|
#do something
end
您可以在Mongoid docs中找到更多信息
【讨论】:
Moped::Collection。 Moped 是 Mongoid 3 的 MongoDB 驱动程序。在 Mongoid 2 中,您可以按照您提供的格式将 map reduce 传递给 Ruby 驱动程序。在 Mongoid 3 中,map/reduce 是从一个类或标准中调用的,而不是从一个集合中调用的。