结构数据库公司的FireStore帖子
问题描述:
实时X公司的FireStore数据库结构结构数据库公司的FireStore帖子
体系结构的帖子在实时:在实时
Posts
--ID_USER_1
----IdPost1
------Date
------Image
---IdPost2
------Date
------Image
---IdPost3
------Date
------Image
--ID_USER_2
----IdPost1
------Date
------Image
---IdPost2
------Date
------Image
---IdPost3
------Date
------Image
邮政系统模型。要在公司的FireStore结构中,它可能是这个样子:
Post
--ID_POST1
----Id_user1
----Image
--ID_POST2
----Id_user2
----Image
从我在公司的FireStore明白有收藏的制约,因为转换成实时的相同的结构时,它不会因为我们可以工作没有两个集合,例如:mDB.collection(“Posts”)。collection()。
在用户之间构建发布系统的最佳方式是什么?
谢谢!
答
在Cloud Firestore中,您必须在文档和集合之间进行切换,但我不相信这会对您的数据结构造成问题。
例如,你可以有:
- `posts` [collection]
- `ID_USER_1` [document]
- `posts` [subcollection]
- `ID_POST_1` [document]
- `Date` [field]
- `Image` [field]
- `ID_POST_2` [document]
- `Date` [field]
- `Image` [field]
所以让所有的用户,你可以做的文章:
db.collection('posts').doc('user1234').collection('posts').get()
// OR
db.collection('posts/user1234/posts').get()
由于云计算公司的FireStore也有快速和强大的查询,你也可以将您的所有帖子存储在一个顶级posts
收藏和存储UserId
作为该帖子的财产:
- `posts` [collection]
- `ID_POST_1` [document]
- `UserId` [field]
- `Date` [field]
- `Image` [field]
- `ID_POST_2` [document]
- `UserId` [field]
- `Date` [field]
- `Image` [field]
然后为用户获取所有帖子,你可以这样做:
db.collection('posts').where('UserId', '==', 'user1234')