【发布时间】:2023-03-26 06:22:01
【问题描述】:
我正在尝试为一个简单的社交媒体概念创建一个简单的 Cloud Firestore 数据库结构。
每个用户最多可以拥有一个可以随时更新的帖子(“最喜欢”的帖子除外)。用户“最喜欢”的帖子版本会保存为单独的帖子,只要用户在当前版本的帖子中收到的点赞数超过最喜欢的版本,就可以随时更新。
我想出了一个结构,但我对 NoSQL 数据库非常缺乏经验。这个结构看起来会支持我的系统吗?还有这些明显的问题会阻止重要的查询吗?
USERS (collection)
DocumentID - userId gathered from Authentication uid
firstName: String
lastName: String
username: String
birthdate: Timestamp
accountCreationDate: Timestamp
post: postId (when user is created, create a default post document for them since there is only one post per user)
bestPost: postId
FRIENDS (subcollection)
DocumentID - userId of the friend
username: String
POSTS (collection)
DocumentID - postId randomly generated
authorUserId: String
authorUsername: String
text: String
imagePath: String
location: String
likesCount: Number
LIKES (subcollection)
DocumentID - userID of the liker
username: String
friends 子集合存储了朋友的用户名,因此通过用户名创建该用户的朋友列表很容易。我假设我可以通过将朋友的 documentID 与 users 中的 documentID 进行匹配来获取该用户朋友的更多信息。
类似的喜欢子集合
【问题讨论】:
标签: firebase firebase-realtime-database nosql google-cloud-firestore