我为帖子创建了评论模型。嵌套的注释可以包含多个层次。为此,我在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)
进行查询。但是,如何遍历所有级别的评论呢?你能给我个主意吗?