我正在尝试根据哈希中的一些预先计算的值更新RethinkDB中的多个文档.即
给定一个stats带有主键的表,其中slug包含数据
[{slug: 'foo', stats: {}}, {slug:'bar', stats:{}}]
Run Code Online (Sandbox Code Playgroud)
给出一个像Hash这样的值的Hash
updated_stats = {
'foo' => {a: 1, b: 2},
'bar' => {a: 3, b: 4}
}
Run Code Online (Sandbox Code Playgroud)
我可以做这个
updated_stats.each{|k,v|
r.table('stats').get(k).update{|s|
{ :stats => v }
}
}
Run Code Online (Sandbox Code Playgroud)
那么,为什么我不能做以下事情呢?
r.table('stats').get_all(*updated_stats.keys).update{|s|
{ :stats => updated_stats[s["slug"]] }
}
Run Code Online (Sandbox Code Playgroud)
rql显示nil为updated_stats [s ["slug"]]的值.真的很感激任何帮助.谢谢.
尝试运行时出现以下错误 berks install
$ berks install
Resolving cookbook dependencies...
Fetching 'collectd' from https://github.com/librato/collectd-cookbook.git (at master)
Fetching 'collectd-librato' from https://github.com/librato/collectd-librato-cookbook.git (at master)
Fetching 'influxdb' from https://github.com/svs/chef-influxdb.git (at master)
Fetching 'monit' from https://github.com/apsoto/monit.git (at master)
Fetching 'nginx_conf' from https://github.com/firebelly/chef-nginx_conf.git (at master)
Fetching 'papertrail-rsyslog' from https://github.com/hipsnip-cookbooks/papertrail-rsyslog.git (at master)
Fetching 'rvm' from https://github.com/fnichol/chef-rvm.git (at master)
Fetching 's3cmd' from https://github.com/fred/chef-s3cmd.git (at master)
Fetching cookbook index from https://supermarket.getchef.com...
/Users/svs/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/json/common.rb:155:in `encode': "\xE2" on US-ASCII (Encoding::InvalidByteSequenceError)
from /Users/svs/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/json/common.rb:155:in `initialize'
from /Users/svs/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/json/common.rb:155:in `new'
from /Users/svs/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/json/common.rb:155:in `parse'
from /Users/svs/.rvm/gems/ruby-2.1.0@kirana/gems/ridley-4.0.0/lib/ridley/chef/cookbook/metadata.rb:458:in `from_json' …Run Code Online (Sandbox Code Playgroud)