This is the end result I would like to get.
{
'_id': '2022-08-06',
'users': [
{
'id': '345456',
point: 1,
},
],
};
I'm trying these, but it doesn't work. Thank you very much for your reply.
client.db(dbProject).collection('test').updateOne({ '_id': data.id, users: { $elemMatch: { id: data.id2 } } })
client.db(dbProject).collection('test').findOneAndUpdate(
{
'_id': data.id,
users: { $elemMatch: { id: data.id2 } },
},
{ $addToSet: { 'users': { id: data.id } }, $inc: { 'users.point': decimal(String(data.point)) } },
{
upsert: true,
})