Firestore社交网络数据结构 [英] Firestore social network data structure

查看:55
本文介绍了Firestore社交网络数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何构建社交网络数据库结构(例如 twitter ),我们可以在其中跟踪用户并在其时间轴中获取其所有推文,我已经检查了此Firestore-如何构建Feed和跟踪系统,但帖子中的解决方案似乎有缺陷.

How to structure a Social Network database structure like for example twitter where we can follow a users and get all their tweets in our timeline, i have already checked this Firestore - how to structure a feed and follow system but the solutions in the post look flawed.

Firestore是不同的,它需要冗余数据才能有效地访问数据,但是假设我正在跟踪1000个人,并且如果我需要通过查询我正在关注的每15个用户的数据并使用来获取所有这些用户的信息,limit(10)方法,然后 orderBy(timeStamp)在查询之间可能有未读的帖子,因为我们使用 last post timeStamp 来获取帖子,如何在Firestore中为社交媒体应用构建数据

Firestore is different where it requires redundant data to access data efficiently, but suppose i am following 1000 people and if i need to get the posts of all those users by querying data for each 15 users i am following and using limit(10) method then orderBy(timeStamp) there may be unread posts between Queries, because we are getting the post using the last post timeStamp , how to structure the data for a social media app in Firestore

推荐答案

在NoSQL数据库上对用例进行建模时,您倾向于针对应用程序的功能和频繁的读取操作进行优化.

When modeling a use-case on a NoSQL database, you tend to optimize for the features of your application, and for frequent read-operations.

因此,在社交媒体应用程序中,您的主要功能可能是用户看到他们关注的每个人的最新帖子.要针对频繁阅读优化此操作,您需要将每个用户应该在该用户的文档中看到的帖子存储.因此,与Twitter相比,您几乎会有一个包含每个用户的Twitter feed的文档.或者,如果单个文档的数据过多,则可能需要将其放入集合中.我经常将其解释为在数据库中为应用程序的屏幕建模.

So in a social media application your main feature may be that the user sees the recent posts of everyone they follow. To optimize this operation for frequent reads, you'll want to store the posts that the each user should see in a document for that user. So when compared to Twitter, you'd pretty much have a document containing the twitter feed for each user. Or if there's too much data for a single document, you might want to put that in a collection. I often explain this as modeling the screens of your app in the database.

这与关系数据库中的典型数据模型有很大不同,因此习惯于花些时间是很正常的.为了获得良好的介绍,我建议:

This is very different from the typical data model in a relational database, so it's normal that it takes time to get used to. For a good introduction, I recommend:

  • Reading NoSQL data modeling.
  • Watching Firebase for SQL developers, even though it's for the Realtime Database, it explains how to map common SQL concepts to Firebase's NoSQL model.
  • Watching Getting to know Cloud Firestore

这篇关于Firestore社交网络数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆