MongoDB :: 数据库设计
我正在使用 MongoDB。我有用户,我有东西。用户可以关注或喜欢这些内容,并且他也可以关注另一个用户。 我应该在哪里存储喜欢和关注的列表? 在 SQL 中,这是一个带有关注/类型/关注的表的 JOIN 调用,但在 Mongo 中,嗯......我只是不知道。
我想到的选项:
一个带有以下/类型/后面的集合,每个都有一个DBref
存储数据两次,一次在用户集合中,一次在事物集合中。这个的可维护性看起来很糟糕,查询也是如此。
I'm using MongoDB. I have Users and I have Things. A user can follow or like those things and he can also follow another user. Where should I store the list of likes and follows? In SQL that was a JOIN call with a table of following / type / followed, but in Mongo, well... I just don't know.
Options I think of:
A collection with following / type / followed, each has a DBref
Storing the data twice, once in the users collection and once in the things collection. The maintainability of this looks bad and so does querying.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议使用选项 1,因为您可能需要进行一些计算。
MapReduce 目前仅适用于一个集合。提供统计数据也更容易。
我并没有真正使用 DBref,但到目前为止,这种方法对我来说效果很好。
I would suggest option 1 since you might need to do some computation.
Map reduce works only on one collection for now. It's also easier to provide stats.
I don't really use DBref but this approach has owrked pretty well so far for me.