Mongo realm function $push on array and $set on others

I need to update a document which has data like below (with nested arrays (books → images ). I want to make updates to fields like say books-> favorite and also add/delete images to books->images

userid: "ABC123"
books: Array
   0:Object
       BookId:"082392519186"
       favorite:false
       images:Array
              0:Object
                ImgId:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA/wAAAI+CAMAAAA2KPHCAAAA..."
              1:Object
                "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA/wAAUAl//lHTWwDyK0ECT/KUP/////..."

Below is my code; Please check my comments against the line about the issues I am facing.

 var oInputMessages= {
   ImgId: arg.ImgId
},
filter2 = {
    'userid': arg.id,
    'books.BookId': arg.BookId
  },
updatevar = 
      {
        $set: {   'books.
```: 
                {
                'BookId': arg.BookId,
                'favorite': arg.myFav,
     //$push: {images: [oInputMessages]} //Error: The dollar ($) prefixed field '$push' in 'books.1.$push' is not valid for storage
    // 'images': [oInputMessages]       //Always overwriting the entry. so only one entry remains
                } 
              },
        //$push: {'books.
```: {images: oInputMessages}}    //Error: Updating the path 'books.
``` would create a conflict at 'books.
      $push: {images: oInputMessages}                     //Adds image each time just fine BUT places "images" array outside of "books" array. I want books[].images[].ImgId
  },

options = {upsert: true};

var doc = user_books_collection.findOneAndUpdate(filter2, updatevar, options, function (err, data) {
if (err) {
return res.status(500).send(err);
}
if (!data) {

    return res.status(404).end();
}
return res.status(200).send(data);
**Alternatively, I tried below;**

I have the below two functions (one that does $set and another one that does $push on the same collection (user_books)) and they work fine stand alone. But when I wrap them both in another fucntion and call them one after the other, for some reason it is always overwriting the image with the latest one and NOT ADDING the image.

//This function does a $set and it work fine on its own
var updateRatingsAndComments = context.functions.execute(“fnUpdateFavoriteBook”, arg);

//This function uploads the image using $push. When I call this function individually it ADDS the image each time I call this and so it is fine on its own.
var uploadUserBookImage = context.functions.execute(“fnUploadUserBookImage”, arg);

But when I wrap both the functions like below (because I want to do both operations in one shot), it is overwriting the previous image and NOT ADDING.

fnUpdateUserRatingsAndComments

exports = async function(arg)
{

var updateFavoriteBook = context.functions.execute(“fnUpdateFavoriteBook”, arg);
var uploadUserBookImage = context.functions.execute(“fnUploadUserBookImage”, arg);

};