Firestore 查询 - 一对多关系

AD *_*ark 6 android nosql firebase firebase-realtime-database google-cloud-firestore

我将开发 android 移动应用程序并使用 Firebase 作为后端。我是 NoSql Firestore 的新手。

在我的应用程序中,用户有很多主题。一个主题有很多帖子,帖子有很多评论和一张图片。用户也有很多追随者。

在这种情况下,如何根据我的要求设计 Firestore 数据库以及最佳实践是什么?如何减少阅读次数?

以下结构适合我的要求吗?

Firestore-root
    |
    --- Topic (collections)
    |     |
    |     --- topicId (document)
    |            |
    |            --- topicId: "345"
    |            |
    |            --- title: "Topic Title"              
    |            |
    |            --- viewCount: 20
    |            |
    |            --- likeCount: 30
    |            |
    |            --- Posts (colletion)
    |            |     |
    |            |     --- postId
    |            |            |
    |            |            ---postId: "321"
    |            |            |
    |            |            ---Title: "My title"
    |            |            |
    |            |            --- Image: ' '
    |            |            |
    |            |            --- commentsCount: 1
    |            |            |
    |        |            --- comments (colletion)
    |            |          |
    |            |           --- commentId
    |            |                             |
    |            |                            ---commentId: "123"
    |            |                        |
    |            |                   ---comment: "My Comment"
    |            |                             |    
    |            --- likes (colletion)
    |            |     |
    |            |     --- likeId (document)
    |            |            |
    |            |            --- userId: true
    |            | 
    |         
    |
     --- Users (collections)
    |     |
    |     --- userId (document)
    |            |
    |            --- userId: "345"
    |            |
    |            --- name: "Test Name"              
    |            |
    |            --- followersCount: 20
    |            |
    |            --- followingCount: 30
Run Code Online (Sandbox Code Playgroud)

Ale*_*amo 7

作为一个简短的答案,是的,对于您的特定要求,我觉得不错。我今天早些时候已经回答了一个问题,这几乎和你的一样,我提供了一个与你已经拥有的类似的数据库模式。但是您需要知道构建 Cloud Firestore 数据库没有完美的解决方案。最好的解决方案是满足您的需求并使您的工作更轻松的解决方案。但是对于这种结构,我发现您可以轻松查询以获取所有必要的数据,因此在我看来,继续这样做。