2

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

######工作代码
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
######Desired 但不工作的代码
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 调用它

4

0 回答 0