title: How to project more than one value with doctrine mongodb query builder selectElemMatch
body: <p>I have the following kind of data in my mongo database. The property "values" consists of an array of attributes. "values" is a property of a product, which also has some other properties like "normalizedData". But the structure of "values" is what gives me a headache.</p>
  
  <pre><code>"values" : [
      {
          "_id" : ObjectId("5a09d88c83218b814a8df57d"),
          "attribute" : NumberLong("118"),
          "entity" : DBRef("pim_catalog_product", ObjectId("59148ee283218bb8548b45a8"), "akeneo_pim"),
          "locale" : "de_AT",
          "varchar" : "LED PAR-56 TCL 9x3W Short sw"
      },
      {
          "_id" : ObjectId("5a09d88c83218b814a8df57a"),
          "attribute" : NumberLong("118"),
          "entity" : DBRef("pim_catalog_product", ObjectId("59148ee283218bb8548b45a8"), "akeneo_pim"),
          "locale" : "de_DE",
          "varchar" : "LED PAR-56 TCL 9x3W Short sw"
      },
      {
          "_id" : ObjectId("5a09d88c83218b814a8df57c"),
          "attribute" : NumberLong("184"),
          "entity" : DBRef("pim_catalog_product", ObjectId("59148ee283218bb8548b45a8"), "akeneo_pim"),
          "locale" : "de_AT",
          "boolean" : false
      },
      {
          "_id" : ObjectId("5a09d88c83218b814a8df585"),
          "attribute" : NumberLong("118"),
          "entity" : DBRef("pim_catalog_product", ObjectId("59148ee283218bb8548b45a8"), "akeneo_pim"),
          "locale" : "fr_FR",
          "varchar" : "LED PAR-56 TCL 9x3W Short sw"
      },
      {
          "_id" : ObjectId("5a09d88c83218b814a8df584"),
          "attribute" : NumberLong("121"),
          "entity" : DBRef("pim_catalog_product", ObjectId("59148ee283218bb8548b45a8"), "akeneo_pim"),
          "locale" : "fr_FR",
          "varchar" : "Eurolite LED PAR-56 TCL 9x3W Short sw"
      },
      {
          "_id" : ObjectId("5a09d88c83218b814a8df574"),
          "attribute" : NumberLong("207"),
          "entity" : DBRef("pim_catalog_product", ObjectId("59148ee283218bb8548b45a8"), "akeneo_pim"),
          "varchar" : "51913611"
      },
  ]
  </code></pre>
  
  <p>A couple of things to notice about this extract from the dataset:</p>
  
  <ul>
  <li>attributes with their ID ("attribute") can appear multiple times, like 118 for example. </li>
  <li>attributes do not always have the same subset of properties (see 207 and 121 for example).</li>
  <li>if an attribute is present multiple times (like 118) it should differ in the "locale" property at least.</li>
  </ul>
  
  <p>Now I need the doctrine mongoDB query builder to project the following result:</p>
  
  <ul>
  <li>I want only those attributes to be present in the result that contain one of the IDs specified by the query (e.g. array(118, 184)).</li>
  <li>If the attribute exists multiple times, I want to see it multiple times.</li>
  <li>If the attribute exists multiple times, I want to limit the number by an array of locales given.</li>
  </ul>
  
  <p>So an example query would be: return all attributes inside "values" that have eigther 118 or 184 as the "attribute" property, and (if specified) limit the results to those attributes, where the locale is either "de_DE" or "it_IT".</p>
  
  <p>Here is what I have tried so far:</p>
  
  <pre><code>$qb = $productRepository-&gt;createQueryBuilder();
  $query = $qb
      -&gt;hydrate(false)
      -&gt;select(array('normalizedData.sku'))
      -&gt;selectElemMatch(
          'values',
          $qb-&gt;expr()-&gt;field('attribute')-&gt;in(array(117, 110))-&gt;addAnd(
              $qb-&gt;expr()-&gt;field('locale')-&gt;in(array('it_IT', 'de_DE'))
          ))
      -&gt;field('_id')-&gt;in($entityIds)
      -&gt;field('values')-&gt;elemMatch($qb-&gt;expr()-&gt;field('attribute')-&gt;in(array(117, 110)))
      -&gt;limit($limit)
      -&gt;skip($offset);
  </code></pre>
  
  <p>This query always returns only one attribute (no matter how many times it is present within the "values" array) per product. What am I doing wrong here?</p>
  
  <p>EDIT: My MongoDB version is 2.4.9 and doctrine-mongo-odm is below 1.2. Currently I cannot update either.</p>