gpt4 book ai didi

android - Firestore 查询 - 一对多关系

转载 作者:行者123 更新时间:2023-11-29 16:38:08 25 4
gpt4 key购买 nike

我打算开发安卓移动应用程序并使用 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

最佳答案

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

关于android - Firestore 查询 - 一对多关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52044566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com