我想构造一个表单的查询:
select * from some_table
where
(field1 = 'x' or field2 = 'y')
and
(field3 = 'z' or field4 = 'w')
通过阅读文档,我认为它应该看起来像这样Mongoid
:
SomeTable.or({:field1 => 'x'}, {:field2 => 'y'})
.and # or is it .intersect?
.or({:field3 => 'z'}, {:field4 => 'w'})
但这不起作用 - mongo 选择器只是所有字段的“$or”。这样做的正确方法是什么?谢谢。
我也很欣赏相反的情况,例如 - 如何执行此查询:
select * from some_table
where
(field1 = 'x' and field2 = 'y')
or
(field3 = 'z' and field4 = 'w')