Update a nested array with many elements in a nested array

I have a db that looks like this :

{
    "_id": "637c648fb8fcfb2bc3071bb9",
    "consultant_name": "Sam smith",
    "consultantUsername": "sam",
    "consultant_Password": "123",
    "type": "consultant",
    "clients": [
        {
            "client_name": "john",
            "client_Username": "mouh",
            "client_Password": "123",
            "type": "client",
            "documents": [
                {
                    "name": "Passeport",
                    "description": "copie conforme certifié de tout le passeport",
                    "doc_upload": "Capture dâeÌcran, le 2022-11-28 aÌ 23.01.12.png",
                    "_id": "637c648fb8fcfb2bc3071bbb"
                },
                {
                    "name": "Acte de naissance",
                    "description": "Pour prouver la filiation",
                    "doc_upload": "_Abstract  Aesthetic CD Album Cover Art.png 637c648fb8fcfb2bc3071bbc",
                    "_id": "637c648fb8fcfb2bc3071bbc"
                }
            ],
            "_id": "637c648fb8fcfb2bc3071bba"
        },

As you can see, Sam smith has different clients and each of those clients have different documents. My goal is to be able to allow Sam to add one more client to his portfolio AND specify the documents (as many as he wants) of that new user created all at once (when Sam creates a new user in the db). The process I used is to update his client list by creating a new client.

Here’s the code to add a client (that works), please note that the document part doesn’t get updated :

router.put("/:id", async(req,res)=>{
  
  try {
   const updateUser = await User.findByIdAndUpdate(req.params.id, {
      
        $push: {
          clients:{ 
          client_name: req.body.client_name,
          client_Username: req.body.client_Username,
          client_Password: req.body.client_Password,
//documents not updating even with one single entry
    documents : [ 
           {
            name : req.body.docName,
            description : req.body.docDescription,
            doc_upload : req.body.doc_upload,
          }
        ]

          
          
          }
        }

        },{new:true});
               res.status(200).json(updateUser);
        
      }
     catch(err) {
      res.status(500).json(err);
    }
  });

So my instinct here would be to push documents using the $each operator, but because the document update doesn’t work I’m kind of stuck. In an ideal world if you have the answer/reflexion to be able to update the document part with multiple values it would be appreciated. Any idea on what to do or where should I look first ?

Thank you

Most likely

because

is a string and your User document _id is an ObjectId.