title: Filter a find by the last element on an embedded array
body: <p>In MongoDB how can I do a search that is filtered by a predicate applied on the last element of an embedded array?</p>
  
  <p>I know if I wanted to do it on the first one I could do this:</p>
  
  <pre><code>db.inventory.find( { 'instock.0.qty': { $lte: 20 } } )
  </code></pre>
  
  <p>As specified on the <a href="https://docs.mongodb.com/manual/tutorial/query-array-of-documents/" rel="nofollow noreferrer">documentation</a>.</p>
  
  <p>How do I write an analog query that looks at the last element, when I don't know the exact size of the embedded array?</p>