title: Mongoose: Aggregate query in a nested array structure
body: <p>I'm getting a little issue with a Mongo DB query.</p>
  
  <p>I have a collection called "Answers" with the following structure</p>
  
  <pre><code>{
    "_id": ObjectId("560acfcb904a29446a6d2617"),
    "path_id": ObjectId("560acae1904a29446a6d2610"),
    "step_id": "kids",
    "user_id": ObjectId("559ae27684ff12e88d194eb7"),
    "answers": [
      {
        "id": "kids_q",
        "question": "Do you have kids?",
        "answer": "No"
      }
    ]
  }
  </code></pre>
  
  <p>As you can see <code>answers</code> is an array and it can have one or many objects, but always is an array.</p>
  
  <p>First, I want to get the total of answers in a step_id</p>
  
  <p>I get that using the following query using aggregate</p>
  
  <pre><code>Answer.aggregate( {
          $match: {
              'path_id': {
                  $eq: path_id
              },
              'step_id': {
                  $eq: step_id
              },
              ''
  
          }
      }, {
          $group: {
              _id: {
                  step_id: '$step_id'
              },
              count: {
                  $sum: 1
              }
          }
      }, function( err, results ) {
          if ( err ) {
              deferred.reject( err );
          }
          deferred.resolve( results );
      } );
  </code></pre>
  
  <p>That works great.</p>
  
  <p>Second, I want to get how many of that answers match against the question and the answer.</p>
  
  <p>Let's use the <code>Do you have kids?</code> question as example, I want to know how many answers are <code>Yes</code>, running a query in the command line I get the correct result:</p>
  
  <pre><code>db.answers.find( {
      path_id: ObjectId( '560acae1904a29446a6d2610' ),
      'answers.0.question': 'Do you have kids?',
      'answers.0.answer': 'Yes'
  } )
  </code></pre>
  
  <p>I want to translate that query into an aggregate query using mongoose and avoid to have hard coded the array <code>answers.0.question</code> because that answer can be stored in a random index, maybe in the index 1, maybe in the index 7.</p>
  
  <p>Any help is appreciated.</p>
  
  <p>Thanks</p>