title: Update nested subdocuments in MongoDB with arrayFilters
body: <p>I need to modify a document inside an array that is inside another array.
  I know MongoDB doesn't support multiple '$' to iterate on multiple arrays at the same time, but they introduced <strong>arrayFilters</strong> for that.
  See: <a href="https://jira.mongodb.org/browse/SERVER-831" rel="nofollow noreferrer">https://jira.mongodb.org/browse/SERVER-831</a></p>
  
  <p>MongoDB's sample code:</p>
  
  <pre><code>db.coll.update({}, {$set: {“a.$[i].c.$[j].d”: 2}}, {arrayFilters: [{“i.b”: 0}, {“j.d”: 0}]})
  Input: {a: [{b: 0, c: [{d: 0}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}
  Output: {a: [{b: 0, c: [{d: 2}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}
  </code></pre>
  
  <p>Here's how the documents are set:</p>
  
  <pre><code>{
      "_id" : ObjectId("5a05a8b7e0ce3444f8ec5bd7"),
      "name" : "support",
      "contactTypes" : {
          "nonWorkingHours" : [],
          "workingHours" : []
      },
      "workingDays" : [],
      "people" : [ 
          {
              "enabled" : true,
              "level" : "1",
              "name" : "Someone",
              "_id" : ObjectId("5a05a8c3e0ce3444f8ec5bd8"),
              "contacts" : [ 
                  {
                      "_id" : ObjectId("5a05a8dee0ce3444f8ec5bda"),
                      "retries" : "1",
                      "priority" : "1",
                      "type" : "email",
                      "data" : "some.email@email.com"
                  }
              ]
          }
      ],
      "__v" : 0
  }
  </code></pre>
  
  <p>Here's the schema:</p>
  
  <pre><code>const ContactSchema = new Schema({
      data: String,
      type: String,
      priority: String,
      retries: String
  });
  
  const PersonSchema = new Schema({
      name: String,
      level: String,
      priority: String,
      enabled: Boolean,
      contacts: [ContactSchema]
  });
  
  const GroupSchema = new Schema({
      name: String,
      people: [PersonSchema],
      workingHours: { start: String, end: String },
      workingDays: [Number],
      contactTypes: { workingHours: [String], nonWorkingHours: [String] }
  });
  </code></pre>
  
  <p>I need to update a contact. This is what I tried using arrayFilters:</p>
  
  <pre><code>Group.update(
      {},
      {'$set': {'people.$[i].contacts.$[j].data': 'new data'}},
      {arrayFilters: [
          {'i._id': mongoose.Types.ObjectId(req.params.personId)},
          {'j._id': mongoose.Types.ObjectId(req.params.contactId)}]},
      function(err, doc) {
          if (err) {
              res.status(500).send(err);
          }
          res.send(doc);
      }
  );
  </code></pre>
  
  <p>The document is never updated and I get this response:</p>
  
  <pre><code>{
      "ok": 0,
      "n": 0,
      "nModified": 0
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>