1
Class Tweet
  field :lD,    as: :load_date,           type:Time
  field :t,     as: :text, type:String
end

Tweet.where({:text=>{ $in: ["champ","looser"]},:load_date.gte=>1.month.ago}) #OR
Tweet.where({:text=>{ $all: ["champ","looser"]},:load_date.gte=>1.month.ago}) #AND

in 和 all 都可以应用于 Array 而不是 String 类型的字段,就像我的情况一样。那么是否可以在 where 子句中使用条件而不是迭代每个元素

4

1 回答 1

-1

While the $all can only be applied to arrays, this is not the case for $in.

What might be causing your problem is that the first query will only match the text exactly, have you tried something like:

Tweet.where({:text=>{ "$in" =>  [/champ/,/looser/]},:load_date.gte=>1.month.ago.utc})
于 2013-07-24T11:25:43.457 回答