title: How to get embedded document in an array in MongoDB (with Mongoose)
body: <p>I have a BSON object like this saved in MongoDB:</p>
  
  <pre><code>{
    "title": "Chemistry",
    "_id": "532d665f89ae4ae703b29730",
    "__v": 0,
    "sections": [
    {
      "week": 1,
      "_id": "532d665f89ae4ae703b29731",
      "assignments": [
      {
        "created_date": "2014-03-22T10:30:55.621Z",
        "_id": "532d665f89ae4ae703b29733",
        "questions": []
      },
      {
        "created_date": "2014-03-22T10:30:55.621Z",
        "_id": "532d665f89ae4ae703b29732",
        "questions": []
      }
      ],
      "materials": []
    }
    ],
    "instructor_ids": [],
    "student_ids": []
  }
  </code></pre>
  
  <p>What I wish to do is to retrieve the 'assignment' with _id 532d665f89ae4ae703b29731. It is an element in the assignments array, which, in turn, is an element in the sections array.</p>
  
  <p>I am able to retrieve the entire document with the query </p>
  
  <blockquote>
    <p>{ 'sections.assignments._id' : assignmentId }</p>
  </blockquote>
  
  <p>However, what I want is just the assignment subdocument</p>
  
  <pre><code>{
  "created_date": "2014-03-22T10:30:55.621Z",
  "_id": "532d665f89ae4ae703b29733",
  "questions": []
  }
  </code></pre>
  
  <p>Is there a way to accomplish such query? Should I resolve to have assignment in a different collection?</p>