Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 344
Hagay albo Avatar asked Oct 29 '25 14:10

Hagay albo


1 Answers

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

like image 110
Grisha Kotler Avatar answered Oct 31 '25 13:10

Grisha Kotler