I know i've had this issue in the past and i was able to solve it, i just dont know how exactly anymore.
this is to update any reason on a case, i know mongodb has a built in function but i cant find anything on it so i just replace the entire array, but both console logs return the same array even though i haven't touched doc.cases.
export const updateReason = async (guild: string, count: number, reason: string) => {
const coll = db.collection('moderation')
const q = {guild: guild}
let doc = await coll.findOne(q)
if(!doc) return
let arr: Array<any> = [...doc.cases]
let el = arr.filter((c : any) => c.count == count)[0]
let index = arr.indexOf(el)
if(index == -1) return;
el.reason = reason;
arr.splice(index, el)
console.log(doc.cases)
console.log(arr)
await coll.updateOne(doc, {
$set: {
cases: arr
}
})
}