title: Updating nested array inside array mongodb
body: <p>I have the following mongodb document structure:</p>
  
  <pre><code>[
      {
          "_id": "04",
          "name": "test service 4",
          "id": "04",
          "version": "0.0.1",
          "title": "testing",
          "description": "test",
          "protocol": "test",
          "operations": [
              {
                  "_id": "99",
                  "oName": "test op 52222222222",
                  "sid": "04",
                  "name": "test op 52222222222",
                  "oid": "99",
                  "description": "testing",
                  "returntype": "test",
                  "parameters": [
                      {
                          "oName": "Param1",
                          "name": "Param1",
                          "pid": "011",
                          "type": "582",
                          "description": "testing",
                          "value": ""
                      },
                      {
                          "oName": "Param2",
                          "name": "Param2",
                          "pid": "012",
                          "type": "58222",
                          "description": "testing",
                          "value": ""
                      }
                  ]
              }
          ]
      }
  ]
  </code></pre>
  
  <p>I have been able to use $elemMatch in order to update fields in operations, but when I try to do the same thing (modified) for parameters it does not seem to work. I was wondering what other approach should I look into trying in order to be able to successfully update fields in a specific parameter, looking it up by its pid. </p>
  
  <p>The update code I currently have and does not work looks like this:</p>
  
  <pre><code>var oid = req.params.operations;
  var pid = req.params.parameters;
  
  collection.update({"parameters":{"$elemMatch": {"pid": pid}}},{"$set": {"parameters.$.name":req.body.name, "parameters.$.description": req.body.description,"parameters.$.oName": req.body.oName,"parameters.$.type": req.body.type} }, function(err, result) {
          if (err) {
              console.log('Error updating service: ' + err);
              res.send({'error':'An error has occurred'});
          } else {
              // console.log('' + result + ' document(s) updated');
              res.send(result);
          }
      });
  </code></pre>