I have created a comment section in my react app. The comment section has following data structure in the firestore:-
comments: [{
comment: "First comment",
replies: [{
reply: "first reply"
}]
},{
comment: "Second comment",
replies: [{
reply: "first reply"
}]
}]
If I want to add a new comment I do this by: -
db.collection("myCollection").doc("0").update({
comments: firebase.firestore.FieldValue.arrayUnion({
comment: "New Comment",
replies: []
})
})
Now, what I actually want to do is to do is to add a new reply to the existing comment. But I can't find any way to do it. For example, I want this to happen in the data structure defined above: -
comments: [{
comment: "First comment",
replies: [{
reply: "first reply"
},{
reply: "second reply"
}]
},{
comment: "Second comment",
replies: [{
reply: "first reply"
}]
}]
So how can I do this?
Please help me solve this. Thank you!