title: Pymongo: How to access the field value of an object in a nested array in a Projection?
body: <p>I'm trying to code a projection in pymongo (3.3.0, Python 3.6.0, MongoDB 3.2).</p>
  
  <p>The original data is approximately of the form:</p>
  
  <pre><code>{
      "_id" : ObjectId("592fd5ac1aee05abb6104912"),
      "Results" : {
              "SomeData" : 1234,
              "ResultAllPoints" : {
                  "MyArray" : [
                       {
                           "Value" : 0.5,
                           "Result" : 1,
                       },
                       {
                            "Value" : 1.5,
                            "Result" : 1,
                       }
                       {
                            "Value" : 1.7,
                            "Result" : 1,
                       }
                  ]
              }
      }
  }
  </code></pre>
  
  <p>I want to access the value stored in the field "Value" the <em>second</em> array entry of "MyArray" and use it as the value of a new field. </p>
  
  <p>Using the MongoDB Shell, the command</p>
  
  <pre><code>db.my_collection.findOne().Results.ResultAllPoints.myArray[1].Value
  </code></pre>
  
  <p>gives me exactly the value I want to have in my resulting collection. </p>
  
  <p>However, in my projection code, neither</p>
  
  <pre><code>{"newName" : "$Results.ResultAllPoints.myArray[1].Value"}
  </code></pre>
  
  <p>nor</p>
  
  <pre><code>{"newName" : "$Results.ResultAllPoints.myArray.1.Value"}
  </code></pre>
  
  <p>are working. In the first case, "newName" does not appear in the result at all the second case results in an empty array as the content of "newName". </p>
  
  <p>I already know that I can use </p>
  
  <pre><code>{"$arrayElemAt": [ "$Results.ResultAllPoints.MyArray", 1]} 
  </code></pre>
  
  <p>to access the Object containing the required information. But how can I access the content of "Value" afterwards?</p>
  
  <p>Any help would be greatly appreciated! :) </p>
  
  <p>EDIT: This is not a duplicate of <a href="https://stackoverflow.com/questions/3985214/retrieve-only-the-queried-element-in-an-object-array-in-mongodb-collection">Retrieve only the queried element in an object array in MongoDB collection</a>, as I don't know the content of "Value" beforehand and therefore cannot use '$elemMatch'.</p>