【问题标题】:How do you update a document based on an index in RavenDB?如何根据 RavenDB 中的索引更新文档?
【发布时间】:2012-10-22 17:46:54
【问题描述】:

以 Stack Overflow 标记系统为例,如何获取标记对象及其计数?

鉴于这些实体:

// Represents the data from the TagCount index
public class TagCount
{
    public string Tag { get; set; }
    public int Count { get; set; }
}

// Represents the data used to populate a tag-wiki
public class Tag
{
    public string Tag { get; set; }
    public DateTime Created  { get; set; }
    public string Description { get; set; }
}

public class Question
{
    // elided
    public List<string> Tags { get; set; }
    // elided
}

以及下面对TagCount索引的定义

// Map
from question in docs.Questions
from Tag in question.Tags
select new { Tag, Count = 1 }

// Reduce
from result in results
group result by result.Tag into g
select new 
{
    Tag = g.Key,
    Count = g.Sum(x=>x.Count)
}

在标签页面(例如https://stackoverflow.com/tags)上,我们需要显示标签集合和 TagCounts 索引的组合。也就是说,我们需要显示来自 Tags 集合的 Tag.Name 和 Tag.Description 以及来自 TagCount 索引的 TagCount.Count。在 SQL Server 中,这将通过连接来实现,但这显然是关系思维方式。实现此目的的惯用 RavenDB 方式是什么?

有没有办法将 Count 属性添加到 Tag 实体并让索引自动更新该属性?

【问题讨论】:

    标签: ravendb


    【解决方案1】:

    您可以通过修补来做到这一点,在 API 中也称为 UpdateByIndex。 你可以在这里看到这个: http://blog.hibernatingrhinos.com/12705/new-option-in-the-ravendb-studiondash-patching

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-30
      • 1970-01-01
      • 2019-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多