To illustrate, We have a nested array object in object
const Clubs= new Schema({
{cid: 1,
c_name: "Fenerbahce",
c_players: [
{
pid: 1,
p_name: "Elif Elmas"
},
{
pid: 2,
p_name: "Victor Moses"
}
]
}
]}
})
/*We have player id variable: incomingID*/
const { body : { incomingID } } = req;
const data = Clubs.cplayers.find(x => x.pid == incomingID);
console.log(data)
{pid: 1,
p_name: "Elif Elmas"
}