Using a combination of ANDs and ORs in Mongoid

天大地大妈咪最大 提交于 2019-12-05 10:27:46

It seems I needed to use a combination of mongo and Mongoid syntax (the $something operator):

SomeTable.and( :$or => [ { :field1 => 'x' }, { :field2 => 'y' } ])
         .and( :$or => [ { :field3 => 'z' }, { :field4 => 'w' } ]) 

The inverse of that is just replacing the operators:

SomeTable.or( :$and => [ { :field1 => 'x' }, { :field2 => 'y' } ])
         .or( :$and => [ { :field3 => 'z' }, { :field4 => 'w' } ]) 

Hope this helps someone :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!