MongoDB 使用 C# Fluent 聚合框架的异常

MongoDB exception using C# Fluent Aggregation Framework

我正在尝试编写一个非常简单的分组查询,在 C# 驱动程序中使用 MongoDB 流畅的聚合语法。

我按作者对文档进行分组,return计算每个作者的数量。我不需要 return 作者姓名,只需要计数。下面的代码可以编译,但是当我执行它的时候,我得到了这个异常:

Command aggregate failed: the group aggregate field name '$sum' cannot be an operator name.

var query = Collection<TestFile>()
    .Aggregate()
    .Group(
        t => t.AuthorName,
        grp => grp.Count()
     )
     .ToEnumerable();

MongoDB版本:3.2.4

MongoDB C#驱动版本:2.2.3.3

像这样试一试(虽然还没有测试)

var query = Collection<TestFile>()
    .Aggregate()
    .Group(
        t => t.AuthorName,
        grp => new { Count = grp.Count() }
     )
     .ToEnumerable();