title: How to get the Current document value with arrayElemAt in Mongo DB
body: <p>I have a sample data</p>
  
  <pre><code>    instock:[ 
         { warehouse: "A", qty: 5 }, 
         { warehouse: "C" },
         { warehouse: "B",qty: 6 },
   ] }
  </code></pre>
  
  <p>in my case i have three arrays, i want to get the <code>instock.qty</code> for index 1 which is null, but am getting the value <code>6</code> instead of null. please let me know what am doing wrong here</p>
  
  <p>this is the query which i have written</p>
  
  <pre><code>db.foo.aggregate([
    { $project: { 
  
        qty: { $arrayElemAt: [ "$instock.qty", 1] }
  
        } }    
  ]);
  </code></pre>
  
  <p>As of my understanding there is no <code>qty</code> field in index <code>1</code> so it is skipping the index <code>1</code> and going to index <code>2</code>. how to over come this problem.</p>