我有这样的课
class Todo
TAG_REGEX = /(?:^|\s)#(\w+)/i
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::FullTextSearch
field :desc, type: String
field :done, type: Boolean, default: false
field :tags, type: Array
end
我正在尝试像这样映射/减少标签
map = %Q{
function() {
this.tags.forEach(function(tag){
emit(tag, { count: 1 });
}
}
}
reduce = %Q{
function(key, values) {
var result = { count: 0 };
values.forEach(function(value) {
result.count += value.count;
});
return result;
}
}
@map = Todo .map_reduce(map, reduce).out(replace: "tags")
当我尝试迭代结果时,我看到了这个异常
The operation: #<Moped::Protocol::Command
@length=480
@request_id=316
@response_to=0
@op_code=2004
@flags=[]
@full_collection_name="todozen_development.$cmd"
@skip=0
@limit=-1
@selector={:mapreduce=>"todos", :map=>"\n function() {\n this.tags.forEach(function(tag){\n emit(tag, { count: 1 });\n }\n }\n ", :reduce=>"\n function(key, values) {\n var result = { count: 0 };\n values.forEach(function(value) {\n result.count += value.count;\n });\n return result;\n }\n ", :query=>{}, :sort=>{"created_at"=>-1}, :out=>{:replace=>"tags"}}
@fields=nil>
failed with error "ns doesn't exist"
我在这里想念什么?
有人需要更多信息吗?
谢谢