I'm trying to build a Mongo query where I can select documents based on the value inside a child array where the embedded array's keys will change from document to document.
In the following example, we have three document arrays. Pulling the name of each wine is trivial. The problem comes when I want to select the wines that have tasting results greater than 20. The problem is that I don't know the name of the flight when I run the query; it could be anything.
Therefore, I can't just check against the values of the embedded array.
I've thought about something like
$ary_query = array('tasting_results.*' => '$gt: 20');
but apparently wildcards don't work in Mongo (at least not like that). Any ideas?
Here's the example arrays:
ary_wines = array(
"name" => "Ripple",
"year" => "2013",
"style" => "cabernet",
"size" => "750ml",
"tasting_results" => array (
"flight_42" => 12,
"flight_2" => 18,
"flight_33" => 7
)
)
ary_wines = array(
"name" => "Riunite",
"year" => "2012",
"style" => "White Zinfandel",
"size" => "1.5L",
"tasting_score" => array (
"flight_6" => 14,
"flight_54" => 21,
"flight_98" => 3
)
)
ary_wines = array(
"name" => "Maneschewitz",
"year" => "2012",
"style" => "Grape Juice",
"size" => "500ml",
"tasting_score" => array (
"flight_7" => 12,
"flight_41" => 26,
"flight_9" => 3
)
)