title: Updating nested arrays in mongoDB via mongo shell
body: <p>Following is a MongoDB document:</p>
  
  <pre><code>{
      "_id" : 2,
      "mem_id" : M002,
      "email" : "xyz@gmail.com",
      "event_type" : [ 
          {
              "name" : "MT",
              "count" : 1,
              "language" : [ 
                  {
                      "name" : "English",
                      "count" : 1,
                      "genre" : [ 
                          {
                              "name" : "Action",
                              "count" : 6
                          }, 
                          {
                              "name" : "Sci-Fi",
                              "count" : 3
                          }
                      ],
                      "cast" : [ 
                          {
                              "name" : "Sam Wortington",
                              "count" : 2
                          }, 
                          {
                              "name" : "Bruce Willis",
                              "count" : 4
                          }, 
                          {
                              "name" : "Will Smith",
                              "count" : 7
                          }, 
                          {
                              "name" : "Irfan Khan",
                              "count" : 1
                          }
                      ]
                  }
              ]
          }
      ]
  }
  </code></pre>
  
  <p>I'm not able to update fields that is of type array, specially event_type, language, genre and cast because of nesting. Basically, I wanted to update all the four mentioned fields along with count field for each and subdocuments. The update statement should insert a value to the tree if the value is new else should increment the count for that value.<br>
  What can be the query in mongo shell?
  Thanks</p>