If I have two queries that look like:
Store.any_in(:store_id => @user.stores_followed)
Store.any_in(:store_id => @category.stores)
How do I join these into an OR using any_of? I tried this and it doesn't. I tried
Store.any_of({:store_id.any_in => @user.stores_followed},
{:store_id.any_in => @category.stores})
It looks like it isn't full supported in Mongoid, so I had to do:
Store.any_of({"store_id" => { "$in" => @user.stores_followed}}, {"store_id" =>
{"$in" => (:store_id => @category.stores)}})
You pass an $or query an array of $in conditions like so:
Store.or( { :store_id.in => @user.stores_followed }, { :store_id.in => @category.stores } )
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