获取firestore中每个帖子的用户喜欢和总喜欢的所有帖子的列表
此问题与查询firestore和实现类似系统并为 firestore 中的每个帖子计数没有点赞的最佳方法有关。
This question is related to querying firestore and best approach for implementing like system and counting no of likes for each post in firestore.
假设我们有一个集合,称为帖子,顶,评论,主题标签。
Let us say we have collection called posts, likes, comments, hashtags. Which has json structure like this.
posts:[{ likes [{
postId:id postId:,
createdAt:date userId,
title:string, collectionType:'posts',
description,string likedAt:date
updatedAt,date }]
createdUser:userId
updatedUser:userId,
}]
comments:[{ hashtags [{}]
postId,
userComments:[{
userId:,
comment:'',
commentedAt:''
replies:[{}]
}]
-
用用户注释
以及嵌套的每个注释的回复来改善
的系统的最佳方法是什么拥有数百万个用户和帖子时的效率和性能。
What is best approach to implement like system with user comments along with nested replies for each comment in which improves efficiency and performance when we have millions of users and posts.
查询所有喜欢的帖子,是否喜欢登录过的用户
每个帖子以及评论和评论计数,获取每个
评论(如果有)的回复。
Querying all posts with likes count on it and like whether logged in user like each post along with comments and comments count, fetching replies per comment if available.
我的方法是否适用于firestore?或者也可以使用任何最佳的数据建模
设计。
Is that my approach will work for firestore ? Or any best data modelling design also possible.
我们是否需要将标签存储在同一集合
的单独集合中,即
Do we need to store hashtags in separate collection of in same collection i.e while create post, inside post object with hashtags array.
我是Firestore的新手,我想学习查询数据在消防站。
根据我对mongodb的了解,我想在firestore中进行探索。在我遇到问题的情况下,请帮助我。
I'm newbie to firestore, I want to learn querying data in firestore. On basis of my knowledge in mongodb, I want to explore in firestore. Please help me in my problem case. Any suggestions or guidance is highly appreciated.
谢谢
-
我建议您创建一个
个帖子
的子集合,称为评论
,将每个帖子的评论放在帖子文档中。您也可以对评论进行评论。您可以创建评论
子集合的子集合,也称为评论
。如果可以在所有子集合中查询评论,则可以轻松地在单个查询中获取所有这些数据。
I would suggest that you create a sub-collection of
posts
calledcomments
and put the comments for each post, inside the post document. You can do the same with comments of comments. You can create a sub-collection of thecomments
sub-collection, also calledcomments
. When it becomes possible to query for comments in all sub-collections, you'll easily be able to get all of this data in a single query.
在您的点赞
收藏文档,我将更改 userId
字段,并将其替换为 createdUserId
和 likedUserId
。然后,您可以查询特定用户帖子或用户的所有赞。
In your likes
collection documents, I would change the userId
field and replace it with createdUserId
and likedUserId
. Then you can query for all likes by a particular user's posts or all likes by a user.
这完全适合Cloud Firestore
This is entirely a good fit for Cloud Firestore
您应该具有#标签的集合。您还需要将帖子中使用的主题标签存储在值映射,以允许查询。
You should have a collection of hashtags. You will also need to store the hashtags used in a post, in a map of values, to allow querying.