Tag: mongodb ruby

如何以编程方式获取Mongoid写入的当前数据库?

我使用Mongoid和rails使用Mongoid.override_database(“database_name”)与多个数据库进行通信。 如何以编程方式查找当前数据库? 关于会话的Mongoid文档: http ://mongoid.org/en/moped/docs/driver.html定义覆盖数据库的方法,但没有定义获取当前正在使用的数据库的方法。

Ruby组按键值散列

我有一个数组,由MongoDB执行的map / reduce方法输出,它看起来像这样: [{“minute”=>30.0, “hour”=>15.0, “date”=>5.0, “month”=>9.0, “year”=>2011.0, “type”=>0.0, “count”=>299.0}, {“minute”=>30.0, “hour”=>15.0, “date”=>5.0, “month”=>9.0, “year”=>2011.0, “type”=>10.0, “count”=>244.0}, {“minute”=>30.0, “hour”=>15.0, “date”=>5.0, “month”=>9.0, “year”=>2011.0, “type”=>1.0, “count”=>204.0}, {“minute”=>45.0, “hour”=>15.0, “date”=>5.0, “month”=>9.0, “year”=>2011.0, “type”=>0.0, “count”=>510.0}, {“minute”=>45.0, “hour”=>15.0, “date”=>5.0, “month”=>9.0, “year”=>2011.0, “type”=>10.0, “count”=>437.0}, {“minute”=>0.0, “hour”=>16.0, “date”=>5.0, “month”=>9.0, “year”=>2011.0, “type”=>0.0, “count”=>469.0}, {“minute”=>0.0, “hour”=>16.0, “date”=>5.0, “month”=>9.0, “year”=>2011.0, “type”=>10.0, “count”=>477.0}, {“minute”=>15.0, “hour”=>16.0, “date”=>5.0, […]