I'm trying to convert this query into an array, so i can use in PHP, but i'm stuck with the 'index' problem... As you can see, i need multiples '$or', because each '$or' validates a set of fields, and i can't join them all in the same '$or'.
Here is the query object:
{
'$and' : [
{ '$or' : [
{'author' : { '$exists' : false } }
, {'author' : { '$in' : [ 'john' , false ] } }
] }
, {'$or' : [
{ '$and' : [ { 'type' : 'post' } , { 'user_id' : 123456 } ] }
, { 'type' : 'comment' }
] }
, { '$or' : [
{ 'tags.name' : { '$in' : [ 'tag1' , 'tag2' ] } }
, { 'tags' : false }
, { 'tags' : { '$exists' : false } }
] }
]
}
The first set of '$or' validates the 'author' field, so i'm searching any document with 'john' or false in the field, and i want the documents that doesn't have the 'author' field. The second set validates the 'type' field, where i need the documents that have 'comment' as value or 'post' AND the 'user_id' is 123456. The third set validates the 'tags' field, where i need some 'tags.name' inside an '$in' or 'tags' = false or 'tags' doesn't exists...
These 3 sets must be true, that's why they're all in the '$and' operator... I'm aware that '$and' works only in 2.0+, but i'm using 2.1 (aggregation frawework testing... it just ROCKS! XD)
I think that's it... if there's another way of writing the query i would reeeally like to see... thanks!