This question is different from other similar questions because { upsert: true } option doesn't give desired output. I want to update/insert the given below document:
{
_id: {
playerId: '1407081',
tournamentId: '197831',
matchId: '1602732'
},
playerName: 'abcd',
points: -5
}
After executing the given below code,
await Points.findOneAndUpdate(
{
"_id": playerStatsObjForDB._id
},
{
playerStatsObjForDB
},
{
upsert: true
}
);
//where playerStasObjForDB is same as object mentioned in top.
if the document doesn't exist, it inserts the following document:
{
"_id": {
"playerId":"1407081",
"tournamentId":"197831",
"matchId":"1602732"
},
"__v":0,
}
I am using mongoose, but any help is greatly appreciated.