如何迭代评论集合以获取所有不同级别的评论回复?

时间:2020-06-02 15:49:29

标签: javascript firebase google-cloud-firestore

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

0 个答案:

没有答案