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?