and my code looks like this
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.
'user' is the object of JWT verification and I want to icncerement user.id by 1 inside object in attendance array. the document looks like this -
_id:ObjectId(some Id)
classId: 'id'
attendance:[
{
date:(value of Date.now()),
userId_1:0,
userId_2:0,
.
.
.
},
{...},
{...},
]