RavenDB 对列表属性进行 Map/Reduce
刚刚学习 Map/Reduce,我错过了一个步骤。我读过这篇文章(使用 .NET 客户端的 RavenDB Map-Reduce 示例 )但无法完全跳转到我需要的内容。
我有一个对象:
public class User : IIdentifiable
{
public User(string username)
{
Id = String.Format(@"users/{0}", username);
Favorites = new List<string>();
}
public IList<string> Favorites { get; protected set; }
public string Id { get; set; }
}
我想要做的是获取所有用户的 Map/Reduce 收藏夹属性。像这样的东西(但这显然不起作用):
Map = users => from user in users
from oil in user.Favorites
select new { OilId = oil, Count = 1 };
Reduce = results => from result in results
group result by result.OilId into g
select new { OilId = g.Key, Count = g.Sum(x => x.Count) };
例如,如果用户 1 有收藏夹 1, 2, 3,用户 2 有收藏夹 1,2,那么这应该返回 {{OilId=3, Count =1}, {OilId=2, Count = 2}, {OilId=1,Count = 2}}
当前代码产生异常: System.NotSupportedException : Node not support: Call
我觉得我 关闭。有什么帮助吗?
Just learning Map/Reduce and I'm missing a step. I've read this post ( RavenDB Map-Reduce Example using .NET Client ) but can't quite make the jump to what I need.
I have an object:
public class User : IIdentifiable
{
public User(string username)
{
Id = String.Format(@"users/{0}", username);
Favorites = new List<string>();
}
public IList<string> Favorites { get; protected set; }
public string Id { get; set; }
}
What I want to do is get Map/Reduce the Favorites property across all Users. Something like this (but this obviously doesn't work):
Map = users => from user in users
from oil in user.Favorites
select new { OilId = oil, Count = 1 };
Reduce = results => from result in results
group result by result.OilId into g
select new { OilId = g.Key, Count = g.Sum(x => x.Count) };
For example, if User1 has favorites 1, 2, 3 and User 2 has favorites 1,2, then this should return back {{OilId=3, Count =1}, {OilId=2, Count = 2}, {OilId=1,Count = 2}}
The current code produces an exception: System.NotSupportedException : Node not supported: Call
I feel like I'm close. Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我编写了一个复制您的代码的小应用程序,但我没有看到抛出的异常。请在此处查看我的代码:http://pastie.org/2308175。输出是
这是我所期望的。
I wrote a small application replicating your code, but I don't see the exception thrown. See my code here: http://pastie.org/2308175. The output is
which is what I would expect.
博尼格,
Map/Reduce 仅适用于跨文档进行聚合。对于这样的事情,通过执行以下操作会得到更好的服务:
MBonig,
Map/Reduce is only useful for doing aggregation across documents. For something like this, you would be served far better by doing something like: