搜索字段类型哈希MongoID的多个键

时间:2013-07-24 06:35:46

标签: ruby-on-rails mongodb ruby-on-rails-3.2 rubygems mongoid

我想在字段类型哈希参考示例代码的多个键上应用过滤器

######工作代码
class Model
  include Mongoid::Document

  field :lD,    as: :load_date,       type:Time
  field :cls,   as: :classification,  type:Hash

  def self.base_filter(filters)
    Model.where("cls.#{filters}.r"=>true,"cls.#{filters}.t"=>"news",:load_date.gte=>1.month.ago).count
  end
end
######期望但不是工作代码
class Model
  include Mongoid::Document

  field :lD,    as: :load_date,       type:Time    
  field :cls,   as: :classification,  type:Hash

  def self.base_filter(filters)
    Model.where("cls.#{filters}"=>{'r'=>true,'t'=>"news"},:load_date.gte=>1.month.ago).count
  end
end

是否有类似的东西在MongoID中可用或者它在MongoDB中可用而不是我如何从MongoID调用它

0 个答案:

没有答案