Consider the following code snippet:
const previous = await Sports.findById(sportId);
Upon execution, it yields the data below:
{
_id: "sdsdsds",
name: "sdsdsds",
enabled: true,
markets: [
{
enabled: true,
defId: "LOOKATME",
name: "sdsdsd",
},
{
enabled: false,
defId: "dfsdfdsfs",
name: "sdsdfsdsd",
},
]
}
If I wish to modify the market with a defId of "LOOKATME" and set its enabled status to false using an update function like this:
const modified = await Sports.findByIdAndUpdate(previous, [LOGIC], {new: true});
What steps should be taken to achieve the desired output as shown below?
{
_id: "sdsdsds",
name: "sdsdsds",
enabled: true,
markets: [
{
enabled: false, // this value has been updated
defId: "LOOKATME",
name: "sdsdsd",
},
{
enabled: false,
defId: "dfsdfdsfs",
name: "sdsdfsdsd",
},
]
}