title: MongoDB: Using lean on aggregate function
body: <p>I'm trying to use the <code>lean()</code> option in order to speed up my queries. But when adding it to a query like this:</p>
  
  <pre><code>Pets.aggregate({ $match: { 'Name': 'Floofkins', 'lastMealDate': {$gt: today}}}, function (err, pets){
    if (err) {
      res.status(500).json({'error': err});
      console.log('Could not fetch pets: ' + err);
      return;
    }
      petsHadMealsToday = pets.length;
  }).lean();
  </code></pre>
  
  <p>All I get is <code>TypeError: Cannot read property 'lean' of undefined</code> although <code>pets.length</code> returns the number of pets that matched the query.</p>
  
  <p><s>If I'd remove the <code>match</code> option however and run something like below, it works like a charm.</p>
  
  <pre><code>Pets.aggregate({ 'Name': 'Floofkins', 'lastMealDate': {$gt: today}}, function (err, pets){
        if (err) {
          res.status(500).json({'error': err});
          console.log('Could not fetch pets: ' + err);
          return;
        }
          petsHadMealsToday = pets.length;
      }).lean();
  </code></pre>
  
  <p>I guess I'm missing some fundamental point about how to use <code>match</code> and such, so feel free to educate me!</s></p>