Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.88 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Map/Reduce over sharded data with RavenDB
  2. errors/1/6
  3. {
  4.   "UniqueId": "c62c7e30-8ec7-45af-88e4-da023d796727",
  5.   "ApplicationName": "MyAppName"
  6. }
  7.        
  8. errors/2/6  --Error stored on shard node 2
  9. {
  10.   "UniqueId": "7e0b0f87-9d75-4e70-9fa0-d64a18bc88dc",
  11.   "ApplicationName": "MyAppName"
  12. }
  13.        
  14. public class ApplicationNames : AbstractIndexCreationTask<ErrorDocument, Application>
  15. {
  16.     public ApplicationNames()
  17.     {
  18.          Map = errors => from error in errors
  19.                         select new { error.ApplicationName, Count = 1 };
  20.  
  21.         Reduce = results => from error in results
  22.                             group error by new { error.ApplicationName, error.Count } into g
  23.                             select new { g.Key.ApplicationName, Count = g.Sum(x=> x.Count) };
  24.     }
  25. }
  26.        
  27. session.Query<Application, ApplicationNames>()
  28.    .ToList()
  29.    .Select(new ApplicationNames().Reduce)
  30.    .ToList();