I am using PHP/Mongo to query a data set like the following:
{
description:
{
0:
{level: (some int 0-50)},
1:
{level: (some int 0-50)},
...
n:
{level: (some int 0-50)}
}
}
How do I write the function, in php, that will build a dynamic query that searches for a level 40 and above, using $or and based on the number of description keys (0 ... n)?
What I currently have for a manual query is not working (I have a feeling it's because in some entries description.1, 2, 3 do not exist):
find("$or":{"description.0.level":[40,41,42,43,44,45,46,47,48,49,50],"description.1.level":[40,41,42,43,44,45,46,47,48,49,50],"description.2.level":[40,41,42,43,44,45,46,47,48,49,50],"description.3.level":[40,41,42,43,44,45,46,47,48,49,50]}})
It gives me an error:
Fatal error: Uncaught exception 'MongoCursorException' with message '$and/$or/$nor must be a nonempty array'
So, I need a function that will build the query dynamically, and work :).