title: Mongoose update a deeply nested sub document only having the sub document _id
body: <p>I have the following schema for a grid (evaluation grid). Grid =&gt; Sections =&gt; Criteria =&gt; Levels and I want to update a single Level element.</p>
  <pre><code>const mongoose = require(&quot;mongoose&quot;);
  
  const levelSchema = mongoose.Schema(
    {
      title: {
        type: String,
        required: true,
      },
      value: {
        type: Number,
        required: true,
      },
    },
    { timestamps: true }
  );
  
  exports.Level = mongoose.model(&quot;Level&quot;, levelSchema);
  
  const criterionSchema = mongoose.Schema(
    {
      title: {
        type: String,
        required: true,
      },
      levels: [levelSchema],
    },
    { timestamps: true }
  );
  
  criterionSchema.virtual(&quot;weight&quot;).get(function () {
    return Math.max(this.levels.map((level) =&gt; level.weigth));
  });
  
  exports.Criterion = mongoose.model(&quot;Criterion&quot;, criterionSchema);
  
  const sectionSchema = mongoose.Schema(
    {
      name: {
        type: String,
        required: true,
      },
      criteria: [criterionSchema],
    },
    { timestamps: true }
  );
  
  sectionSchema.virtual(&quot;weight&quot;).get(function () {
    return this.criteria.reduce((acc, criteria) =&gt; acc + criteria.weight, 0);
  });
  
  exports.Section = mongoose.model(&quot;Section&quot;, sectionSchema);
  
  const schema = mongoose.Schema(
    {
      name: {
        type: String,
        required: true,
      },
  
      sections: [sectionSchema],
      code: { type: Number, required: true },
      course: {
        type: mongoose.Schema.Types.ObjectId,
        ref: &quot;Course&quot;,
        required: true,
      },
    },
    { timestamps: true }
  );
  schema.virtual(&quot;weight&quot;).get(function () {
    return this.sections.reduce((acc, section) =&gt; acc + section.weight, 0);
  });
  
  exports.Grid = mongoose.model(&quot;Grid&quot;, schema);
  </code></pre>
  <p>I was able to retrieve a specific Level's Grid with this code :</p>
  <pre><code>Grid.findOne({&quot;sections.criteria.levels._id&quot;: levelId})
  </code></pre>
  <p>So I tried FindOneAndUpdate with this code :</p>
  <pre><code>const grid = await Grid.findOneAndUpdate(
        { &quot;sections.criteria.levels._id&quot;: req.params.levelId },
        {
          $set: {
            &quot;sections.$[].criteria.$[].levels.$[].title&quot;: req.body.title,
          },
        },
        { new: true });
  </code></pre>
  <p>But, it changed ALL the Levels of the grid.</p>
  <p>How can we update a single Level sub, sub, sub document and returns it ?</p>