title: mongodb - writing complex query including ordering in an embedded array
body: <p>I have a collection with documents like this:</p>
  
  <pre><code>{
  "_id" : ObjectId("5a8ec4620cd3c2a4062548ec"),
  "chromosome" : 1,
  "start" : "1",
  "reference" : "A",
  "alternative" : "C",
  "populationFrequencies" : [ 
      {
          "study" : "dbnlvar",
          "population" : "GBL",
          "value" : 0.1
      }, 
      {
          "study" : "genomad",
          "population" : "AF",
          "value" : 0.2
      }, 
      {
          "study" : "genomad",
          "population" : "AFR",
          "value" : 0.3
      }, 
      {
          "study" : "genomad",
          "population" : "AMR",
          "value" : 0.4
      }, 
      {
          "study" : "genomad",
          "population" : "ASJ",
          "value" : 0.2
      }
      {
          "study" : "1kg",
          "population" : "GBL",
          "value" : 0.1
      }, 
      {
          "study" : "1kg",
          "population" : "EUR",
          "value" : 0.15
      }, 
      {
          "study" : "1kg",
          "population" : "SAS",
          "value" : 0.10
      }, 
      {
          "study" : "1kg",
          "population" : "AMR",
          "value" : 0.25
      }, 
      {
          "study" : "1kg",
          "population" : "EAS",
          "value" : 0.7
      }
  ]
  } 
  </code></pre>
  
  <p>Using this criteria:</p>
  
  <ol>
  <li>Study is equal to '1kg'</li>
  <li>Population is in [EUR,SAS,AMR]</li>
  </ol>
  
  <p>I want to find out documents in the collection that meet that ordering the documents in populationFrecuencies array that meet criteria 1 and 2, by field 'value' from lowest to highest, the second lowest value is bigger than 0.10</p>
  
  <p>So, to clarify, in the following example, the document will be shown.</p>
  
  <ul>
  <li>Study 1kg - Population SAS - Value 0.10 </li>
  <li>Study 1kg - Population EUR - Value 0.15 &lt;--- is bigger than 0.10 </li>
  <li>Study 1kg - Population AMR - Value 0.25</li>
  </ul>
  
  <p>Is it possible to express that as a query in mongodb shell?
  Can anyone help me?
  Thanks a lot for your time.</p>