MongoDB的文档设计征求意见(和他们的答复意见) [英] MongoDB document design for comments (and their reply comments)

查看:147
本文介绍了MongoDB的文档设计征求意见(和他们的答复意见)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型,看起来像:

I have a model that looks like:

class Comment {
    public string ID { get; set; }
    public string ArticleType { get; set; }
    public string ArticleID { get; set; }
    public string Body { get; set; }

    public DateTime DateCreated { get; set; }

    public string UserID { get; set; } 
}



我创建一个应用程序来存储有关其他的东西的意见在我们的应用程序
为例,如果注释是对一个产品,ArticleType可能是产品,而条款ArticleID将是产品ID ...

I am creating an app to store comments about other stuff in our application For example, if the comment was regarding a product, the ArticleType could be "product" and the ArticleID would be the product id...

我要使用MongoDB中存储这些数据。

I am going to use mongodb to store this data

我希望能够回复评论,存储响应分级
我应该存储在注释中的列表DOC?

I want to be able to reply to a comment, and store the response hierarchically Should I store a List within the comment doc?

我的阅读罗布阿什顿此文章,其中有意义的事情,比如博客文章,它的评论...

I read this article by Rob Ashton Which makes sense for things like a blog post, and it’s comments...

不过,在我的模型,回复意见直接引用父评论。

However, in my model, the "reply comments" refer directly to the parent comment.

评论回复也可能甚至有答复,使他们的 X 的水平深...?
请问这是出地图的范围,降低类型的查询

Comment replies could also even have replies, making them x levels deep...? Would this be out of the scope of map reduce type query?

编辑:

的文章大概是不好的术语 - articleType和条款ArticleID只是一个绑评论到一个特定的东西的方式 - 例如,如果我们在这个问题上发表评论,articleType可能是stackOverflowQuestion和id会为5144273

"article" is probably bad terminology - ArticleType and ArticleId was just a way of tying a comment to a particular "thing" - for example, if we were commenting on this question, articleType could be stackOverflowQuestion and id would be 5144273

如果我们在一个eBay拍卖评论,我们可以有articleType eBay和条款ArticleID为1234902493984(项目编号)

If we were commenting on an ebay auction, we could have articleType as ebay and articleId as 1234902493984 (item number)

希望这更有意义......

Hopefully that makes more sense...

推荐答案

我看到三个解决方案的更多钞票(这只是我的意见):

I see three posible solutions(it just my opinion):

1

public class Comment 
{
  ...
  public List<Comment> ChildComments {get;set;}
}



优点:你可以很容易的负载,显示分层数据。你不知道从评论父评论。结果
缺点:您无法查询,并与一些标识更新注释

Pros: you can easy load, display hierarchical data. you don't know parent comment from comment.
Cons: you can't query and update comment with some id.

2

public class Comment 
{
  ...
  public string ParentCommentId {get;set;}
}

优点::您可以根据需要查询/更新。结果
缺点:请求金额大,当你需要加载层次来蒙戈

Pros: You can query/update as you want.
Cons: Big amount of requests to mongo when you need load hierarchy.

3.My最爱之一;)

3.My favorite one ;) :

 public class Comment 
 {
   ...
   public string ParentCommentId {get;set;}
 }

 public class Article
 {
   ...
   public List<Comment> Comments {get;set;}
 }



优点:可以查询/更新,只要你想。您可以加载的文章,在一个请求的所有意见。没有必要存储redurant ArticleType和条款ArticleID结果
缺点:需要加载的文章,并在内存中构建层次

Pros: You can query/update as you want. You can load article with all comments in one request. No need to store redurant ArticleType and ArticleId
Cons: Need to load article and build hierarchy in memory.

希望此帮助你做出的选择。

Hope this help you make choice..

这篇关于MongoDB的文档设计征求意见(和他们的答复意见)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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