【问题标题】:RavenDB Get By List of IDs?RavenDB 通过 ID 列表获取?
【发布时间】:2013-11-03 05:25:42
【问题描述】:

在 RavenDB 中

我需要根据文档的 ID 获取文档的最新插入,并按列表中的 ID 过滤

即:

List<Entity> GetLastByIds(List<int> ids);

实体类似于:

class Entity
{
int id; //Unique identifier for the category the price applies to.
int Price; //Changes with time
DateTime Timestamp; //DateTime.UtcNow
}

所以如果我插入以下内容:

session.Store(new Entity{Id = 1, Price = 12.5});
session.Store(new Entity{Id = 1, Price = 7.2});
session.Store(new Entity{Id = 1, Price = 10.3});
session.Store(new Entity{Id = 2, Price = 50});
session.Store(new Entity{Id = 3, Price = 34});
...

如何获取 ID 1 和 3 的最新价格??

我的 Map/Reduce 工作正常,为我提供每个 ID 的最新信息,这是我正在努力解决的过滤问题。 我想在 Raven 中进行过滤,因为如果所有 ID 总共有超过 1024 个价格点,那么在客户端进行过滤是没有用的。

非常感谢我能得到的任何帮助。

提前非常感谢你:)

【问题讨论】:

    标签: ravendb


    【解决方案1】:

    如果Id 应该代表类别,那么您应该将其命名为CategoryId。通过调用属性Id,您正在接受Raven 的约定,即它应该被视为该文档的主键。您不能保存同一文档的多个版本。它只会覆盖上一个版本。

    假设您已正确构建索引,您只需像这样查询它:

    using Raven.Client.Linq;
    
    ...
    
    var categoryIds = new[] {1, 3};  // whatever
    var results = session.Query<Entity, YourIndex>()
                         .Where(x=> x.CategoryId.In(categoryIds));
    

    .In 扩展方法位于Raven.Client.Linq 命名空间中。)

    【讨论】:

    • 这很有魅力,但现在我的索引似乎确实需要帮助。
    猜你喜欢
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    • 1970-01-01
    • 2021-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    相关资源
    最近更新 更多