title: Changing the last value of a nested array in MongoDB
body: <p>I have the following structure</p>
  
  <pre><code>{
      "_id" : 2,
      "mem_id" : M002,
      "email" : "xyz@gmail.com",
      "event_type" : [ 
          {
              "name" : "MT",
              "count" : 2,
              "language" : [ 
                  {
                      "cast" : [ 
                          {
                              "name" : "Some Name 1",
                              "count" : 2
                          }, 
                          {
                              "name" : "Some Name 2",
                              "count" : 4
                          }, 
                      ],
                      key: 0
                  },
                  {
                      "cast" : [ 
                          {
                              "name" : "Some Name 3",
                              "count" : 2
                          }, 
                          {
                              "name" : "Some Name 4",
                              "count" : 4
                          }, 
                      ],
                      key: 1
                  }
  
              ]
          }
      ]
  }
  </code></pre>
  
  <p>I would like to change the value of "Some Name 2". actually it's always going to be the last element of the nested array "cast".</p>
  
  <p>I'm searching for the key value to find the correct index of the language array so I have the positional value.</p>
  
  <p>The question is how can I change the last value of the nested array?</p>
  
  <p>Can I do something like that? (Python)</p>
  
  <pre><code>  const query = {_id: 2, 'event_type.language.key': 0};
    const updateQuery = {$set: {'event_type.language.$.cast.-1.name': "Some Name 4"}};
  
    User.update(
      query,
      updateQuery,
      (err) =&gt; {
        if (err) {
          res.status(404).end();
        } else {
          res.status(200).end();
        }
      }
    );
  </code></pre>