我为帖子创建了一个评论模型。嵌套的注释可以有很多层次。为此,我在comments集合内创建了一个post集合。单个评论文档具有以下结构
content: string,
author: {
username: string,
userID: string
},
isRootComment: bool,
childComments: [id1, id2, id3],
childOfCommentID: string
现在我想以这种方式迭代comments集合,使其在网页上具有以下结构
root-comment:A
child-comment:1
subchild-comment:1
subchild-comment:2
child-comment:2
subchild-comment:1
root-comment:B
child-comment:1
subchild-comment:1
child-comment:2
要获取所有根级注释,我可以查询为where("isRootComment", "==", true). 但是如何迭代所有级别的评论呢?你能给我一个想法吗?