In MongoDB, when trying to express A AND (B OR C), it can easily be done with the following query:
db.demo.find( { a: 1, $or: [ {b:1}, {c:1} ] });
However, if the requirement is to have (A AND B) OR C -- this doesn't seem to work as expected. Using the query below:
db.demo.find( { $or: [ {a:1,b:1}, {c:1} ] });
The above query treats it as A or B or C, which is equivalent to:
db.demo.find( { $or: [ {a:1}, {b:1}, {c:1} ] });
Currently, I am avoiding using Javascript expression $where to achieve this because I am creating general filter rules directly converted into MongoDB queries.
Any suggestions or alternative methods?