title: MongoDB sort by field in embedded that matches query
body: <p>I have documents in MongoDB which look like this</p>
  
  <pre><code>{ 
      "_id": "...",
      "ranks":[
      {"pos": 1,"type":"some type"},
      {"pos": 56,"type":"other type"},
      ...
      ]
  }
  </code></pre>
  
  <p>I want to find all items where 'ranks.type' matches "some type" and sort them by 'pos' in this embedded document.</p>
  
  <p>In SQL I would do something like this (tables document and document_rank)</p>
  
  <pre><code>SELECT
      D.* 
  FROM
      document D 
  JOIN
      document_rank DR ON DR.document_id = D.id
  WHERE
      DR.type="some type" 
  ORDER BY 
      DR.pos
  </code></pre>
  
  <p>I'm just asking if I can do this by embedding ranks or I have to link them to document. My experiments show that I have to link.</p>