【问题标题】:Mongoid replacement for MySQL's DateTime field tools like select * from posts where HOUR(posted) = 01Mongoid 替换 MySQL 的 DateTime 字段工具,例如 select * from posts where HOUR(posted) = 01
【发布时间】:2012-04-02 12:07:15
【问题描述】:

我正在尝试使用 Mongoid 将 MySQL 支持的应用程序移植到 MongoDB。一些重要的查询使用 MySQL 的 DateTime 工具,例如:

select * from posts where HOUR(posted) = 01

张贴的是完整的 DateTime 时间戳。如何使用 Mongoid 实现这一点?

【问题讨论】:

    标签: mysql ruby-on-rails ruby ruby-on-rails-3 mongoid


    【解决方案1】:

    MongoDB 在内部使用 Javascript。您可以发送一段 Javascript 代码作为过滤器:

    posts = Post.where("this.posted.getHours() == 1")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-07
      • 2012-11-17
      • 1970-01-01
      • 2012-12-11
      • 2019-05-16
      • 2012-01-25
      相关资源
      最近更新 更多