Search code examples
mapreduceravendb

How do I add the first and last value in a map reduce RavenDB index


When having a map reduce I would like to also include the first value of user current balance and last value of user balnce ordered by the date

from r in results
group r by new {r.Date, r.UserId} into g
select new
{
    Date = g.Key.Date,
    UserId = g.Key.UserId,
    Count = g.Sum(x => x.Count),
   ** StartBalance = g.First(x=>x.Balance),
    EndBalance = g.Last(x => x.Balance)**

}

I am expecting to get the first balance of the user when he just logged in to the game and also the last balance of the same player of the user at the end of the day.

Is this something possible?


Solution

  • This should work: g.OrderyBy(x => x.Date).Select(x => x.Balance).FirstOrDefault()