Increment value inside object in array

the document looks like this -

_id:ObjectId(some Id)
classId: 'id'
attendance:[
   {
   date:(value of Date.now()),
   userId_1:0,
   userId_2:0,
   .
   .
   .
  },
  {...},
  {...},
]

this is my code-

const updateAttendance = await privateClass.findOneAndUpdate({classId:req.body.classId,"attendance.date":date},
                {$inc:{`attendance.$.${user.id}`: 1 }})

the problem is-

`attendance.$.${user.id}`

this line produce errors. I am using mongoose, nodeJs
‘user’ is a object of JWT verification and I want to increase value of user.id by 1.