title: Possible to avoid $unwind / aggregation on large array using $elemMatch and regular query?
body: <p>I have a collection of documents (call it 'logs') which looks similar to this:</p>
  
  <pre><code>{
    "_id" : ObjectId("52f523892491e4d58e85d70a"),
    "ds_id" : "534d35d72491de267ca08e96",
    "eT" : NumberLong(1391784000),
    "vars" : [{
        "n" : "ActPow",
        "val" : 73.4186401367188,
        "u" : "kWh",
        "dt" : "REAL",
        "cM" : "AVE",
        "Q" : 99
      }, {
        "n" : "WinSpe",
        "val" : 3.06327962875366,
        "u" : "m/s",
        "dt" : "REAL",
        "cM" : "AVE",
        "Q" : 99
      }]
  }
  </code></pre>
  
  <p>The <code>vars</code> array holds about 150 subdocuments, not just the two I have shown above. What I'd like to do now is to run a query which retrieves the <code>val</code> of the two subdocuments in the <code>vars</code> array that I have shown above.</p>
  
  <p>Using the aggregation framework, I've been able to come up with the following:</p>
  
  <pre><code>db.logs.aggregate( [ 
      { $match : 
          { ds_id: "534d35d72491de267ca08e96", 
            eT: { $lt : 1391784000 }, 
            vars: { $elemMatch: { n: "PowCrvVld", val: 3 }}
          }
      }, 
      { $unwind : "$vars" }, 
      { $match :
          { "vars.n" : { $in : ["WinSpe", "ActPow"] }}, 
          { $project : { "vars.n" : 1, N : 1}
      } 
  ]);
  </code></pre>
  
  <p>While this works, I run up against the 16MB limit when running larger queries. Seeing as I have about 150 subdocuments in the <code>vars</code> array, I'd also like to avoid <code>$unwind</code> if it's possible. </p>
  
  <p>Using a regular query and using <code>$elemMatch</code> I have been able to retrieve ONE of the values:</p>
  
  <pre><code>db.logs.TenMinLog.find({
      ds_id : "534d35d72491de267ca08e96",
      eT : { $lt : 1391784000 },
      vars : { $elemMatch : { n : "PowCrvVld", val : 3 }
      }
  }, {
      ds_id : 1,
      vars : { $elemMatch : { n : "ActPow", cM : "AVE" }
  });
  </code></pre>
  
  <p>What my question comes down to is if there's a way to use $elemMatch on an array multiple times in the <code>&lt;projection&gt;</code> part of find. If not, is there another way to easily retrieve those two subdocuments without using $unwind? I am also open to other suggestions that would be more performant that I may not be aware of. Thanks!</p>