I’m using Doctrine ODM with mongoDB.
I’m trying to do queries like :
$queryBuilder->field('array_field')->in('even_value_1', 'event_value_2');
$queryBuilder->field('array_field')->in('odd_value_1', 'odd_value_2');
The idea is to select all documents that have in their
array_field(event_value_1 OR event_value_2) AND (odd_value_1 OR odd_value_2)
With the syntax I’m using, I’m getting the documents that have
event_value_1 OR event_value_2 OR odd_value_1 OR odd_value_2
Any ideas on how to proceed or if it is possible ?
It seems that the $and operator is just not currently available in MongoDB.
The $and operator is in 1.9.1 (unstable version)
Here is the ticket for the feature request :
https://jira.mongodb.org/browse/SERVER-1089
Currently (1.8.x) the only solution seems to use multiple “$or” statments like :
EDIT: Here is some code to help future users
First, we need a function to transform our
to
Here are the needed functions
For the Doctrine ODM part :
Hope this helps