data structure in messages
board:"general"
thread:[ {_id:"a",
replies: [{_id:"b", reported:false},
{_id:"c", reported:false},
{_id:"d", reported:false}
] }]
I want to update a reported filed in replies
I used this: (board, thread_id, reply_id) all declared:
messages.updateOne({
board,
"thread._id":thread_id,
"thread.replies._id":reply_id},
{$set:{"thread.replies.$.reported":true}}, (err, data)=>{
console.log(data)
} )
My query matches the document but does not update it. And console returns undefined
If I use this to update:
{$set: {"replies.$.reported":true}
it’s updating the parent document outside the both array
like this:
board:"general"
thread:[]
replies:[{reported:true}] // another field inserted here
I’ve tried few other method of update, but did not work.
Can you give me a simple solution for this?
Thank you.