0

My map:

docs.Visits.Select(obj => new {
    Year = obj.MetaData.CreatedDate.Year,
    Month = obj.MetaData.CreatedDate.Month,
    Day = obj.MetaData.CreatedDate.Day,
    MediaSource = ((System.String)(obj.MediaSource)),
    Version = ((System.String)(obj.Version)),
    Count = 1
})

My reduce:

results.GroupBy(result => new {
    Year = result.Year,
    Month = result.Month,
    Day = result.Day,
    MediaSource = result.MediaSource,
    Version = result.Version
}).Select(agg => new {
    Year = agg.Key.Year,
    Month = agg.Key.Month,
    Day = agg.Key.Day,
    MediaSource = agg.Key.MediaSource,
    Version = agg.Key.Version,
    Count = Enumerable.Sum(agg, x => ((System.Int32)(x.Count)))
})

Example query:

Year: 2012 AND Month: 8 AND Day: 22

Yet I get duplicate items, sometimes even the count is the same, other times they differ only in the counts. The dataset in the Visit collection is roughly 200,000 documents, so it's nothing. I've re-added the index, re-setted it, but still, same odd behaviour.

I mean that I actually get multiple identical map reduces back, like this:

{
  "Year": "2012",
  "Month": "8",
  "Day": "22",
  "MediaSource": null,
  "Version": null,
  "Count": "7701"
}

How can this be possible when I group them by; Year, Month, Day, MediaSource and Version? What's the point with a group by if it doesn't "group by"? At some dates the sum of all counts that day is actually higher than the total amount of Visit documents in the database.

What am I doing wrong?

Database Server Build 960, Client Build 888. .NET RavenDB Client 1.2.2068.

4

0 回答 0