Mongoose: Update does not work in nested array object
<p>I have a document with the array of objects and one object contains multiple objects I want to update inner object with <code>$set</code> but didn't get any luck.
can anybody give me any hint so that I can resolve it?.</p>

<p>This is my object:</p>

<pre><code>{
  "_id": ObjectId("56fbfafdf86fa6161911d104"),
  "site": "xyz",
  "adsPerCategory": NumberInt(2),
  "sampledAt": ISODate("2016-03-30T16:12:45.138+0000"),
  "items": [
    {
      "id": "4563873",
      "content": {
        "title": "WATER DISTILLERS",
        "body": "Perfect to save money.",
      }
    },
    {
      "id": "4563s23232873",
      "content": {
        "title": "Cola water",
        "body": "Perfect for body.",
      }
    }
  ]
}
</code></pre>

<p>I want to update <code>body</code>.</p>

<p>for now, I have given <code>single object</code> but it can be multiple.</p>

<p>Here what I tried</p>

<pre><code>models.Sample.update(
  {
    _id: samples._id
  },
  '$set': {
    'items.0.content.body': body.description
  },
  function(err, numAffected) {
    console.log(err);
    console.log('Affected....', numAffected);
  }
);
</code></pre>

<p>It's working fine if I put <code>0</code> but I want to make it dynamic.</p>

<p>Like <code>'items.index.content.body': body.description</code></p>

<p>Thank You.</p>