Updating nested array field data type int to decimal128

Hi,
working on modifying nested array field data type update many document with single I am able to update data type but some data getting delete

below json structure,

{
    _id:(objectId...)
    student: [
      {
        name: {
          firstName: "Rahul",
          lastName: "khurana",
          Address: "xyz"
        },
        mark: [
          {
            maths: 19,
            english: 10,
            science: 20
          }
        ],
        subject: {
          subjectName: "Maths",
          subjectCode: 1
        }
      },
      {
        name: {
          firstName: "Shahrukh",
          lastName: "khan",
          Address: "xyz"
        },
        mark: [
          {
            maths: 45,
            english: 70,
            science: 100
          }
        ],
        subject: {
          subjectName: "Maths",
          subjectCode: 1
        }
      }
    ]
  }

the query I treid

db.test.updateMany({},
   [
      {
         $set: {
            
            student: {
               $map: {
                  input: "$student",
                  as:"s",
          in:{mark:{$map:{input:"$s.mark",in:{$mergeObjects:["$this",{maths:{$toDecimal:"$this.maths"}}]}}}}
               }
            }
         }
      }
   ]
)

but subject and name objects are getting delete.
can any help me on this ?
thanks in advance

working with this query thanks,

db.test.updateMany({},
   [
      {
         $set: {
            
            student: {
               $map: {
                  input: "$student",
                  as:"s",
          in:{name:"$s.name",mark:{$map:{input:"$s.mark",in:{$mergeObjects:["$this",{maths:{$toDecimal:"$this.maths"}}]}}},subject:"$s.subject"}
               }
            }
         }
      }
   ]
)

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.