MongoDB中的嵌套注释 [英] Nested Comments in MongoDB

查看:144
本文介绍了MongoDB中的嵌套注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MongoDB的新手,试图用它建立一个嵌套的注释系统。
在网络上,你找到了各种文档结构来实现,但我正在寻找一些建议,将使我能够轻松地做以下事情与评论

I'm quite new to MongoDB and trying to build a nested comment system with it. On the net you're finding various document structures to achieve that, but I'm looking for some proposals that would enable me easily to do the following things with the comments


  • 将评论标记为垃圾邮件/已批准,并通过此属性检索评论

  • 按用户检索评论

  • 检索对象/用户的注释计数

除了显示注释外,如果你有任何建议,如何处理这些事情与MongoDB - 或者 - 告诉我寻找一个替代方案,它会很感激!

Besides of course displaying the comments as it is normally done. If you have any suggestions on how to handle these things with MongoDB - or - tell me to look for an alternative it'd be appreciated much!

推荐答案

您是否考虑过将注释存储在需要引用的所有文档中?如果您有该用户的文档,请将该用户的所有评论存储在该文档中。如果您有对象的单独文档,还存储所有注释。从一个关系型世界来的感觉是错误的,你试图有一个给定的数据的一个副本,然后通过ID引用,但即使关系数据库,你必须开始复制数据,如果你想查询运行

Have you considered storing the comments in all documents that need a reference to them? If you have a document for the user, store all of that user's comments in it. If you have a separate document for objects, store all comments there also. It feels sort of wrong after coming from a relational world where you try to have exactly one copy of a given piece of data, and then reference it by ID, but even with relational databases you have to start duplicating data if you want queries to run quickly.

使用此设计,您加载的每个文档都将是完整的。它将拥有您需要的所有数据,并且该集合上的索引将保持快速读取。当你需要更新评论文本时,价格会稍微慢一点,而且更麻烦,因为你需要更新多个文档。

With this design, each document that you load would be "complete". It would have all the data you need, and indexes on that collection would keep reads fast. The price would be slightly slower writes, and more of a headache when you need to update the comment text, since you need to update more than one document.

这篇关于MongoDB中的嵌套注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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