MongoDB 文档设计的评论(及其回复评论)

发布于 2024-10-19 17:36:01 字数 1025 浏览 8 评论 0原文

我有一个如下所示的模型:

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...

我将使用 mongodb 来存储此数据,

我希望能够回复评论,并分层存储响应 我应该在评论文档中存储一个列表吗?

阅读了 Rob Ashton 撰写的这篇文章这对于博客文章及其评论之类的内容是有意义的......

但是,在我的模型中,“回复评论”直接指父评论。

评论回复甚至还可以有回复,使它们变得x层深......? 这是否超出了MapReduce类型查询的范围?

编辑:

“文章”可能是不好的术语 - ArticleType 和 ArticleId 只是将评论与特定“事物”联系起来的一种方式 - 例如,如果我们评论这个问题,articleType 可能是 stackOverflowQuestion id 为 5144273

如果我们对 eBay 拍卖进行评论,我们可以将articleType 设置为 ebay,articleId 设置为 1234902493984(商品编号)

希望这更有意义...

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; } 
}

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...

I am going to use mongodb to store this data

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.

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

Edit:

"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

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

女皇必胜 2024-10-26 17:36:01

我看到三种可能的解决方案(这只是我的意见):

1.

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

优点:您可以轻松加载、显示分层数据。你不知道家长的评论和评论。
缺点:您无法使用某个 ID 查询和更新评论。

2.

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

优点:您可以根据需要查询/更新。
缺点:当您需要加载层次结构时,会对 mongo 发出大量请求。

3.我最喜欢的一个;) :

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

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

优点:您可以根据需要查询/更新。您可以在一个请求中加载包含所有评论的文章。无需存储重复的 ArticleType 和 ArticleId
缺点:需要加载文章并在内存中构建层次结构。

希望这可以帮助您做出选择..

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 favorite one ;) :

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

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

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..

风渺 2024-10-26 17:36:01

评论回复甚至可以有回复,使它们深x级......?

因此,如果您想对此进行建模,最简单的方法是为每个评论提供一个 Comments 属性列表。这为您提供了适合数据的自然层次结构。

这会超出mapreduce类型查询的范围吗?

不。Map 函数只是一个 JavaScript 方法。它可以调用其他方法,它可以递归地遍历一棵树。

您的模型:

关于您提出的模型,让我担心的一件事是您有 ID、ArticleID 和 ArticleType?您到底打算如何访问该对象?您计划建立什么类型的索引?

评论信息是否会在文章范围之外被访问?
您要加载带有“文章”的评论吗?
仅在文章本身内部存储 List 是否有意义?

您可以通过多种方式对此数据进行建模。所以这实际上取决于你想得到什么。您无法针对每个可能的查询进行优化。如果您可以告诉我们您想要快速执行哪些查询和用例,那么就可以更轻松地提供有关数据建模的建议。

Comment replies could also even have replies, making them x levels deep...?

So if you wanted to model this, the easy way to do this is to give each comment a list of Comments property. This gives you a natural hierarchical structure that fits the data.

Would this be out of the scope of map reduce type query?

No. A Map function is just a javascript method. It can call other methods, it can recursively walk a tree.

Your model:

One thing that worries me about your proposed model is that you have an ID and an ArticleID and an ArticleType? How exactly are you planning to access this object? What type of indexes were you planning?

Is the comment information going to be accessed outside the scope of the article?
Are you going to load the comments with the "article"?
Does it make sense to just store a List<Comments> inside of the article itself?

There are several ways you could model this data. So it's really going to depend on what you want to get out. You can't optimize for every possible query. If you can tell us which queries and use cases you want to make fast, then it's easier to provide advice on modeling the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文