Updating nested array of objects within am array of objects

Thank you John,

You are a lifesaver. The manual did help. Again thank you.

Below is the code sample for those with a similar problem to mine.


      const orgUnitId = req.body.ouId;
      const deptId = req.body.deptId;
      const name = req.body.name;
      const url = req.body.url;
      const username = req.body.username;
      const password = req.body.password;

      const result = await OrganisationalUnit.updateOne(
        {
          id: orgUnitId,
        },
        {
          $push: {
            "departments.$[department].repo": {
              name: name,
              url: url,
              username: username,
              password: password,
            },
          },
        },
        { arrayFilters: [{ "department.id": { $eq: deptId } }] }
      );