For example: We have a document like this one;
clubs:{
cid: 1,
cname: "Fenerbahce",
cplayers: [{
pid: 1,
pad: "Elif Elmas",
pgoals: [{
gid: 1,
gtime: 2019-06-20T16:12:51.989+00:00,
gtype: "thisone"
}]
}]
}
const { body : { cid,pid,gid } } = req;
clubs.update(
{
"cid": cid,
"cplayers": {
"$elemMatch": {
"pid": pid, "pgoals.gid": gid
}
}
},
{ "$set": {
"cplayers.$[outer].pgoals.$[inner].gtype": "thisoneUpdated"
} },
{ "arrayFilters": [
{ "outer.pid": pid },
{ "inner.gid": gid }
] }, (err, result) => {
if (err) {
console.log('Error updating service: ' + err);
res.send({'error':'An error has occurred'});
} else {
console.log(result)
}
});
:)