我有两个问题,
Post.where(:group_id.in => group_ids, :deleted => false)
Post.where(:user_id=>user.id,:deleted=>false)
我需要使用或条件组合这些查询.我试过,
Post.where(:deleted => false).or({:user_id=>user.id},{:group_id.in => group_ids})
和
Post.any_of({:group_id.in=>group_ids},{:user_id=>user.id})
,但我没有得到结果.
你可以这样做:
Post.any_of({:group_id.in => group_ids, :deleted => false}, {:user_id => user.id, :deleted => false})
要么:
Post.all_of(:deleted => true, :or => [{:group_id.in => group_ids}, {:user_id => user.id}])
您可以调用selector
这些表达式中的任何一个来查看将生成以获取数据的mongodb查询.