我收到了这个错误:
$ ruby mapreduce.rb
/usr/share/gems/gems/mongo-1.6.4/lib/mongo/collection.rb:618:in `delete': can't convert Symbol into String (TypeError)
from /usr/share/gems/gems/mongo-1.6.4/lib/mongo/collection.rb:618:in `map_reduce'
from mapreduce.rb:21:in `<main>'
使用以下代码:
require 'rubygems'
require 'mongo'
map = "function() { " +
"var keys = [];" +
"for ( item in this['kg'] ) { keys.push(item) }" +
"emit(keys.sort().join(';'), {count: 1})" +
"}"
reduce = "function(key, values) { " +
"var sum = 0; " +
"values.forEach(function(doc) { " +
" sum += doc.count; " +
"}); " +
"return {count: sum}; " +
"};"
out = "stats"
db = Mongo::Connection.new.db("test")
coll = db.collection("snps")
result = coll.map_reduce(map, reduce, out)
result.find.to_a.each do |r|
puts ['{', r['_id'], ':', r['value']['count'].to_i, '}'].join(" ")
end
使用以下 MongoDB 2.2.3。
我做错了什么?