title: Update an element of an Array in a Document in MongoDB with Mongoose
body: <p>I have a MongoDB database whith a collection with this structure:</p>
  
  <pre><code> {
      "_id" : ObjectId("5b670eefe94672265ca59428"),
      "duration" : {
          "start" : ISODate("2018-09-01T00:00:00.000Z"),
          "end" : ISODate("2018-09-01T00:00:00.000Z")
      },
      "title" : "Example title.",
      "description" : "&lt;p&gt;Hi example!&lt;/p&gt;",
      "slug" : "title",
      "insertDate" : ISODate("2018-08-05T14:51:27.194Z"),
      "webData" : [ 
          {
              "_id" : ObjectId("5bb1f082931c536950ade361"),
              "webCode" : "be_mx",
              "categories" : [ 
                  {
                      "_id" : ObjectId("3sdf43f34543et35tret435"),
                      "name" : "Category 1",
                      "webCode" : "be_mx",
                      "slug" : "category-1"
                  },{
                      "_id" : ObjectId("3sdf43f34543et35tretert"),
                      "name" : "Category 2",
                      "webCode" : "be_mx",
                      "slug" : "category-2"
                  }
              ]            
          }
      ],
      "__v" : 6,
      "lastEditionDate" : ISODate("2018-10-01T10:01:38.889Z")    
  }
  </code></pre>
  
  <p>I want to update all documents from this collection that has a categorie with a _id = "3sdf43f34543et35tret435" (in this example the "Category 1"), and I want to update this element category setting, for example, the slug to "category-3". </p>
  
  <p>I tried to do that with this code:</p>
  
  <pre><code>Collection.update({
              "webData.categories": {
                      $elemMatch: {
                          _id: ObjectId("3sdf43f34543et35tret435")
                      }
                  }
              }, {
                  $set: {
                      webData: {
                          "categories.$.slug": "category-3"
                      }
                  }
              }, {
                  multi: true
              }, (err, res) =&gt; {
                  if (err) { console.log(err); }
                  console.log(res);
              });
  </code></pre>
  
  <p>When I execute that, all the documents that have this category are edited but it's wrong because all the related categories are deleted.</p>
  
  <p>Can you help me with this operation?</p>
  
  <p>Thank you!</p>
  
  <p><strong>EDITED:</strong></p>
  
  <p>When I execute in my DB this query: </p>
  
  <pre><code>db.getCollection("scholarships").update({}, 
  { '$set': { 'webData.[].categories.$[category].slug': "nana" } }, 
  { multi: true, arrayFilters: [{ 'category._id': ObjectId("5b719d821f3f1131ec4524f6") }] })
  </code></pre>
  
  <p>Using in this time an arrayFilter, I receive this error:</p>
  
  <p><em>The path 'webData.[].categories' must exist in the document in order to apply array updates."</em></p>