ruby 遍历mongo数据
2015-07-29 11:51
387 查看
next_played_videos = @channel.videos.active.where(:begin_time.gt => begin_time).asc(:begin_time) next_played_videos.each do |video| video.begin_time = begin_time video.end_time = video.begin_time.to_i + video.duration begin_time = video.end_time video.save end
这里使用 each 操作遍历效率比较低,可以使用 Mongoid 的
inc方法批量对指定的字段值进行增减,文档见 http://mongoid.org/en/mongoid/docs/persistence.html。
next_played_videos = @channel.videos.active.where(:begin_time.gt => begin_time).asc(:begin_time) next_played_videos.inc(begin_at: -@video.duration, end_at: -@video.duration)
相关文章推荐
- 嵌Ruby 2 《捆绑》
- 测试驱动开发 Ruby 命令行工具实战
- win7安装ruby on rails开发环境
- 为什么我们应该为Ruby2.0的GC感到excited!
- 关于Ruby的GC
- selinium的ruby版在windows8下安装
- Ruby 中的类和对象
- ruby中数组的常用函数
- Ruby
- 手把手教学:巧用Core Data和RubyMotion开发iOS应用
- Ruby 程序员最要好的朋友
- 安装ruby环境
- Installing MySQL Ruby Gem checking for mysql_ssl_set()... no
- ruby bundle信任goagent证书
- ruby on rails调试技术
- ruby2.2.2在msvc2010上编译
- ruby环境sass编译中文出现Syntax error: Invalid GBK character错误解决方法
- ruby 环境
- Ruby中 respond_to? 和 send 的用法
- Ruby 中的inject方法