Mongo Driver Version: 2.2.4.26
I have the following query that performs some aggregations. If I remove the Contains predicate from my Where clause, the query executes successfully.
I would like to reduce and perform the aggregation on the server before realizing the data into the client memory. The issue I am encountering is when I use Contains in my Where clause, I get the following exception:
$project or $group does not support Sum({document}{ForecastQuantity}).
I would prefer to stay in linq implementation vs. the native if possible:
public class Forecast
{
public int MarkdownGroupId { get; set; }
public List<ForecastData> ForecastArray { get; set; }
...
}
public class ForecastData
{
public int MarkdownNumber { get; set; }
public double ForecastQuantity { get; set; }
...
}
public class Flat
{
public int MarkdownGroupId { get; set; }
public int MarkdownNumber { get; set; }
public double SalesQuantity { get; set; }
...
}
public class FlatProjection
{
public int MarkdownGroupId { get; set; }
public int MarkdownNumber { get; set; }
public double SalesQuantity { get; set; }
...
}
int[] groupIds = new int[]{ 1,2,3 };
var forecastProductDay = _mdb.GetCollection<Forecast>(collectionName);
var forecastProductProjections = forecastProductDay
.AsQueryable()
.Where(x => groupIds.Contains(x.MarkdownGroupId))
.SelectMany(x => x.ForecastArray, (x, fa) => new Flat
{
MarkdownGroupId = x.MarkdownGroupId,
MarkdownNumber = fa.MarkdownNumber,
ForecastQuantity = fa.ForecastQuantity,
...
})
.GroupBy(key => new {key.MarkdownGroupId, key.MarkdownNumber})
.Select(g => new FlatProjection
{
MarkdownGroupId = g.Key.MarkdownGroupId,
MarkdownNumber = g.Key.MarkdownNumber,
SalesQuantity = g.Sum(y => y.ForecastQuantity),
...
})
.OrderBy(x => x.MarkdownGroupId)
.ThenBy(x => x.MarkdownNumber)
.ToList();