I have two queries,
Post.where(:group_id.in => group_ids, :deleted => false)
Post.where(:user_id=>user.id,:deleted=>false)
I need to combine these query using or condition. I tried like,
Post.where(:deleted => false).or({:user_id=>user.id},{:group_id.in => group_ids})
and
Post.any_of({:group_id.in=>group_ids},{:user_id=>user.id})
but I didn't get results.
You can do it like that:
Post.any_of({:group_id.in => group_ids, :deleted => false}, {:user_id => user.id, :deleted => false})
or:
Post.all_of(:deleted => true, :or => [{:group_id.in => group_ids}, {:user_id => user.id}])
You can call selector
on any of these expressions to see mongodb query that will be generated to fetch data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With