私はこのようなクラスを持っています
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"
ここで何が欠けていますか?
誰かもっと情報が必要ですか?
ありがとう