【发布时间】:2021-08-06 12:39:43
【问题描述】:
我在我的 react 应用中创建了一个评论部分。评论部分在firestore中具有以下数据结构:-
comments: [{
comment: "First comment",
replies: [{
reply: "first reply"
}]
},{
comment: "Second comment",
replies: [{
reply: "first reply"
}]
}]
如果我想添加新评论,我会这样做:-
db.collection("myCollection").doc("0").update({
comments: firebase.firestore.FieldValue.arrayUnion({
comment: "New Comment",
replies: []
})
})
现在,我真正想做的是为现有评论添加新回复。但我找不到任何方法来做到这一点。例如,我希望在上面定义的数据结构中发生这种情况:-
comments: [{
comment: "First comment",
replies: [{
reply: "first reply"
},{
reply: "second reply"
}]
},{
comment: "Second comment",
replies: [{
reply: "first reply"
}]
}]
那么我该怎么做呢?
请帮我解决这个问题。 谢谢!
【问题讨论】:
标签: javascript reactjs firebase google-cloud-firestore